flashsplat
4 years ago
Recently ran into an issue where I sent 100+ emails to my gmail smtp relay. I got an error back saying "Too many login attempts, please try again later."

Is it possible to login once and send all the of emails I need too?

Thanks!
ivan
  • ivan
  • 100% (Exalted)
  • Administration
4 years ago
You can use Connect method and send multiple emails in one session like this:

https://www.emailarchitect.net/easendmail/sdk/?ct=smtpclient_connect 


using System;
using EASendMail;

void SendTwoMailsInOneConnection()
{
    try
    {
        SmtpServer oServer = new SmtpServer("myserveraddress");
        // SMTP user authentication
        oServer.User = "myusername";
        oServer.Password = "mypassword";

        // Most mordern SMTP servers require SSL/TLS connection now.
        // ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically.
        oServer.ConnectType = SmtpConnectType.ConnectTryTLS;

        SmtpClient oSmtp = new SmtpClient();
        oSmtp.Connect(oServer);

        SmtpMail oMail = new SmtpMail("TryIt");
        oMail.From = new MailAddress("from@adminsystem.com");
        oMail.To.Add(new MailAddress("to@adminsystem.com"));

        oMail.Subject = "first test email";
        oMail.TextBody = "test body";

        oSmtp.SendMail(oMail);
        Console.WriteLine("first sent");

        oSmtp.Reset();
        oMail.Reset();

        oMail.From = new MailAddress("from@adminsystem.com");
        oMail.To.Add(new MailAddress("another@adminsystem.com"));

        oMail.Subject = "second test email";
        oMail.TextBody = "another body";

        oSmtp.SendMail(oMail);
        Console.WriteLine("second sent");
        oSmtp.Quit();
    }
    catch (Exception exp)
    {
        Console.WriteLine("Exception: {0}", exp.Message);
    }
}
flashsplat
4 years ago
Fantastic. Thank you!

I switched to SendGrid for a short time, but honestly, I like using your library better.
Thanks again.

EXPLORE TUTORIALS

© All Rights Reserved, AIFEI Software Limited & AdminSystem Software Limited.