Unable to send email using smtp implicit SSL server

I wrote an example program by copying the code in this article to KB with a slight change in regard to user information. It uses the corrupted .NET library System.Web.Mail because the new System.Net.Mail does not support implicit SSL. I went and tested it with a Google smtp server on port 465, which is their implicit mail port, and everything works. However, when I gave this to the client to check it on my network, nothing is received sent / received, here is the error:

2013-03-07 15:33:43 - The transport failed to connect to the server. 2013-03-07 15:33:43 - at System.Web.Mail.SmtpMail.LateBoundAccessHelper.CallMethod(Object obj, String methodName, Object[] args) 2013-03-07 15:33:43 - at System.Web.Mail.SmtpMail.CdoSysHelper.Send(MailMessage message) 2013-03-07 15:33:43 - at System.Web.Mail.SmtpMail.Send(MailMessage message) 

I am not very well versed when it comes to SSL email, so my possible theory explains the main reason:

Assuming it uses the correct SMTP server and the right port (SSL port), I wonder if it could be the cause of any of the following reasons:

  • They use SSL on the mail server, but it does not have a certificate installed on the computer where it runs my program, even if it is in the same domain and uses the same email domain as the sender.

  • They use SSL, but they may use NTLM or anonymous authentication, while my program uses basic authentication.

Sorry if I provide a little information, because I myself am quite a stranger in this area, so I am still researching more.

Do you know of any steps that I can take at the end so that my little test program can send an implicit SSL email server using the SMTP server?

Edit: I added the following line to my code to indicate that I am using SSL.

 oMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpusessl", "true"); 
0
source share
2 answers

It may be too late to answer, but check out https://sourceforge.net/p/netimplicitssl/wiki/Home/

You can send mail to port 465 without having to change your code, so many.

On the project wiki page:

 var mailMessage = new MimeMailMessage(); mailMessage.Subject = "test mail"; mailMessage.Body = "hi dude!"; mailMessage.Sender = new MimeMailAddress(" you@gmail.com ", "your name"); mailMessage.IsBodyHtml = true; mailMessage.To.Add(new MimeMailAddress(" yourfriend@gmail.com ", "your friendd name")); mailMessage.Attachments.Add(new MimeAttachment("your file address")); var emailer = new SmtpSocketClient(); emailer.Host = "your mail server address"; emailer.Port = 465; emailer.EnableSsl = true; emailer.User = "mail sever user name"; emailer.Password = "mail sever password" ; emailer.AuthenticationMode = AuthenticationType.PlainText; emailer.MailMessage = mailMessage; emailer.OnMailSent += new SendCompletedEventHandler(OnMailSent); //Send email emailer.SendMessageAsync(); // A simple call back function: private void OnMailSent(object sender, AsyncCompletedEventArgs asynccompletedeventargs) { Console.Out.WriteLine(asynccompletedeventargs.UserState.ToString()); } 
+1
source

Here I use gmail smtp to send mail using C #. See code below. This will give you an idea of ​​how the products work. Replace your gmail settings with your email server settings. Do not worry about security certificates, they will be taken into account by the card itself.

  public static bool SendMail(string to, string subject, string body) { bool result; try { var mailMessage = new MailMessage { From = new MailAddress("your email address") }; mailMessage.To.Add(new MailAddress(to)); mailMessage.IsBodyHtml = true; mailMessage.Subject = subject; mailMessage.Body = body; var userName = "your gmail username"; var password = "your gmail password here"; var smtpClient = new SmtpClient { Credentials = new NetworkCredential(userName, password), Host = smtp.gmail.com, Port = 587, EnableSsl = true }; smtpClient.Send(mailMessage); result = true; } catch (Exception) { result = false; } return result; } 

The piece of code you referenced was rather old and burdened. CDO was used in ASP applications to send letters. I think you cannot scroll down to see

 Article ID: 555287 - Last Review: April 7, 2005 - Revision: 1.0 APPLIES TO Microsoft .NET Framework 1.1 

You are referencing code that is quite old ... anyway, following the code shown, everything will be FINE ...

UPDATE

My bad, I did not read it carefully. But

I leave the code above, as this can help you or any other guy who needs the SSL mailing function through gmail or any other server later.

. Then in this case you will need a third-party application. I found you a library . See here.

0
source

Source: https://habr.com/ru/post/1266387/


All Articles