2013-06-25 124 views
-2

我想從我的C#code.Here發送電子郵件是一個例子從C#代碼發送電子郵件

MailMessage message = new MailMessage(); 
      message.To.Add("[email protected]"); 
      message.Subject = "Registration"; 
      message.From = new System.Net.Mail.MailAddress("[email protected]"); 
      message.Body = "OK"; 
      SmtpClient smtp = new SmtpClient(); 
      smtp.Host = "smtp.gmail.com"; 
      smtp.Send(message); 

但我的代碼休息和這裏的錯誤:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. hn4sm3874638bkc.2 - gsmtp 
+0

你需要使用'NetworkCredential'對象的認證。 – computer10171

回答

2

你必須打開加密。

將這個行前地方smtp.Send()

smtpClient.EnableSsl = true;