Hello everyone, I recently wrote a send to netframework 4.5, everything worked ok, but now I needed 3.0, for some reason, the error SMTP exception on the last line, can anyone write on framework 3.0, tell me pliz.

MailAddress to = new MailAddress ("lala@mail.ru"); MailAddress from = new MailAddress("lololo@gmail.com"); MailMessage mail = new MailMessage(from, to); mail.Subject = "效袝效袝效袝效袝效袝效"; mail.Body = "袥袗袥袗袥袗袥袗袥袗袥"; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 587; smtp.Credentials = new NetworkCredential( "email", "pass"); smtp.EnableSsl = true; Console.WriteLine("Sending email..."); try {smtp.Send(mail);} catch (Exception ex) {Console.WriteLine(ex.Message)} 

Failed to send email

  • By the way .. and 4 also works !!! - markgenuine
  • @markgenuine, in addition to the type of exception, write what Message does this exception have. Take the code in try ... catch. SmtpException occurs when "Connection to SMTP server failed", or "Authentication failed" or "Operation timed out." - Drac5 pm
  • It still does not work, I tried on 3.5 there is no framework), it does not come out - markgenuine
  • @markgenuine, what did you do? I asked you to post a specific error. Catch an exception with a try ... catch block like this: try {smtp.Send (mail);} catch (Exception ex) {Console.WriteLine (ex.Message)}; and put in a question. - Drac5
  • The point is clearly not in the framework version - wind

1 answer 1

In general, there are only 3 options for the occurrence of SmtpException:

  1. Connection to the SMTP server failed - the server is incorrectly specified, or there is no connection to it.
  2. Authentication failed - username / password incorrect. Encryption may be used incorrectly.
  3. Operation time has expired - the connection was established, but the server did not return a response during the time-out.

Check the code for these parameters, for sure there is an error.

  • That's exactly what I tested all these 3 options, but unfortunately I have not yet succeeded, I translate the same project using frame 4.5 and everything works .... - markgenuine
  • So in the last comment wrote what happened. Is not it so? - Drac5
  • In short ... something I do not understand. See what I get, I just took the project, translated it into frame 4.5 sent-it came, then I sent it into the 4-frame, it came, in 3.5,3,2 I try to get the error: "Failed while sending an e-mail message" - markgenuine
  • LOL ..... the problem was in the name of the company .... what was there "-" ... so in the future I will implement sending via sockets .. although there will be no crap with names, thank you all for your support .. - markgenuine 7:18 pm