0 votes

I've an application that uses Limilabs to read emails and it works great. To send emails we use another library that I want to replace by Limilabs, but I'm having problems implementing the sample code, show below, to send email. The settings for the email server that I'm using are correct. It requires SSL and uses port 587. I'm sure of this because these are the same settings that work in the other lib.

try
{
    string _server = ConfigurationManager.AppSettings["SmtpServer"];      
    string _user = ConfigurationManager.AppSettings["UserName"];
    string _password = ConfigurationManager.AppSettings["Password"];
    int _port = Convert.ToInt16(ConfigurationManager.AppSettings["SmtpPort"]);

    IMail email = Mail
         .Text(Text)
         .Subject(Subject)
         .From(new MailBox(ConfigurationManager.AppSettings["From"], "   "))
         .To(new MailBox(To, "   "))                           
         .Create();


    using (Smtp smtp = new Smtp())             
    {

        // THIS SENDS THE EMAIL AND RETURNS "SUCCESS" 
        // BUT I NEVER RECEIVE THE EMAIL IN OUTLOOK
        //smtp.Connect(_server);                 

        // THIS GIVES AUTHENTICATION AS SSL CLIENT FAILED. 
        // You may be connecting to non SSL port.  
        smtp.ConnectSSL(_server, _port);                 

        smtp.UseBestLogin(_user, _password);                  
        SendMessageResult result = smtp.SendMessage(email);

        smtp.Close();
   }
}
catch(Exception ex)
{
    ErrorMsg = ex.Message;
}

}

by (960 points)

1 Answer

0 votes
// THIS SENDS THE EMAIL AND RETURNS "SUCCESS" 
// BUT I NEVER RECEIVE THE EMAIL IN OUTLOOK

If the SMTP's server response is success (SmtpResponse.Status), you should check the recipients spam folder. If the message is not there, contact your server's administrator.

You may show him the logs, so he knows that the server replied with the success status but failed to deliver the message:
https://www.limilabs.com/blog/logging-in-mail-dll

// THIS GIVES AUTHENTICATION AS SSL CLIENT FAILED. 
// You may be connecting to non SSL port.

This error means you are using incorrect port. Don't specify the port manually unless your server is using different than standard (465) port for SSL communication.

It requires SSL and uses port 587. I'm sure of this because these are the same settings that work in the other lib.

You server probably requires explicit SSL (initial connection on unsecured 587 port and STLS command):

smtp.Connect("smtp.example.com");
smtp.StartTLS();

To learn more on how to use SSL/TLS and SMTP please read this article:
https://www.limilabs.com/blog/use-ssl-with-smtp

SSL vs TLS vs STARTTLS is explained in details here:
https://www.limilabs.com/blog/ssl-vs-tls-vs-starttls-stl

Last thing. Using spaces as mailbox name (for From and To addresses) is a bad idea. The server may decide, that you are trying to trick the receiving email client, so it doesn't show email address, and send your message to spam.

by (301k points)
...