服务器拒绝了发件人地址

时间:2015-02-16 12:58:15

标签: c# asp.net

我能够发送带有本地smtp的电子邮件,但在尝试使用gmail发送时,它无法正常工作。

错误:

"The server rejected the sender address. The server response was: 530 5.7.0 
 Must issue a STARTTLS command first. pj7sm14546972pbb.96 - gsmtp\r\n"

C#:

public static void SendEmail()
{
  MailMessage mailMsg = new MailMessage();
  SmtpClient smtpClient = new SmtpClient();
  mailMsg.From = "donotreply@admin.com"; //also tried smtpusername here
  mailMsg.To = strToAddress;
  mailMsg.Subject = strSubject;
  mailMsg.Body = strBody;
  smtpClient.Port = 587;
  smtpClient.EnableSsl = true;
  smtpClient.Credentials = new NetworkCredential(smtpusername, smtppassword);
  //smtpusername & smtppassword are valid gmail credentials
  SmtpMail.SmtpServer = "smtp.gmail.com";
  SmtpMail.Send(mailMsg);
}

1 个答案:

答案 0 :(得分:0)

  

如果EnableSsl属性设置为true,则为SMTP邮件服务器   然后,不会在对EHLO命令的响应中通告STARTTLS   对Send或SendAsync方法的调用将抛出SmtpException。

https://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.enablessl(v=vs.110).aspx