3

当我部署它时,此代码在我的本地机器上运行良好。它给出了Failure sending mail错误..请帮助...

MailAddress addrsTo = new MailAddress(toEmail);
MailAddress addrsFrom = new MailAddress("XXX@XXX.com", "XXX Title");

MailMessage mailmsg = new MailMessage(addrsFrom, addrsTo);
mailmsg.Subject = mailSbjct;

mailmsg.Body = "XXX Body";

SmtpClient smtp = new SmtpClient("mail.XXX.com");
smtp.EnableSsl = false;
smtp.Port = 26;
smtp.Credentials = new NetworkCredential("XXX@XXX.com", "XXXXXXX");

try {
    smtp.Send(mailmsg);
} catch (Exception exc) {
    throw new XXXException(1234, "---" + exc.Message);

}
4

2 回答 2

7

如果您使用的是gmail ,您可以试试这个:

 MailMessage mail = new MailMessage();
 mail.Subject = "Your Subject";
 mail.From = new MailAddress("senderMailAddress");
 mail.To.Add("ReceiverMailAddress");
 mail.Body = "Hello! your mail content goes here...";
 mail.IsBodyHtml = true;

 SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
 smtp.EnableSsl = true;
 NetworkCredential netCre = new NetworkCredential("SenderMailAddress","SenderPassword" );
 smtp.Credentials = netCre;

 try
  {
   smtp.Send(mail);                
  }
  catch (Exception ex)
  {               
  }
于 2013-03-21T06:49:58.027 回答
-1

正如您在问题中提到的,在我的本地机器上运行良好
这表明问题出在您提供用于发送邮件的凭据上。

编辑 1

如果您使用自己的域凭据,那么它将无法在服务器上运行。
用户 IIS 应该有足够的权限来发送邮件。
IIS 用户更多详细信息
http://www.iis.net/learn/get-started/planning-for-security/understanding-built-in-user-and-group-accounts-in-iis

这是一个 SO 链接
如何通过 IIS7 发送电子邮件?

于 2013-03-21T07:01:19.710 回答