C# - 发送邮件失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15541045/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# - Failure sending mail
提问by Arahim
This code works fine on my local machine ut when I deploy it. it gives Failure sending mail
error.. Please Help...
当我部署它时,此代码在我的本地机器上运行良好。它给出了Failure sending mail
错误.. 请帮助...
MailAddress addrsTo = new MailAddress(toEmail);
MailAddress addrsFrom = new MailAddress("[email protected]", "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("[email protected]", "XXXXXXX");
try {
smtp.Send(mailmsg);
} catch (Exception exc) {
throw new XXXException(1234, "---" + exc.Message);
}
采纳答案by Arshad
you can try this, if you are using gmail:
如果您使用的是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)
{
}
回答by ????
As you have mentioned in your question works fine on my local machine.
It is suggesting that the problem is of credential which you are providing to send the mail.
正如您在问题中提到的,在我的本地机器上工作正常。
这表明问题在于您提供的用于发送邮件的凭据。
Edit 1
编辑 1
If you are using you own domain credentialthen it is not going to work on the server.
The user IIS should have enough authority to send mail.
IIS User More detail
http://www.iis.net/learn/get-started/planning-for-security/understanding-built-in-user-and-group-accounts-in-iis
如果您使用的是您自己的域凭据,那么它将无法在服务器上运行。
用户 IIS 应该有足够的权限来发送邮件。
IIS 用户更多详细信息
http://www.iis.net/learn/get-started/planning-for-security/understanding-built-in-user-and-group-accounts-in-iis
Here is a SO link
How to send email through IIS7?
这是一个 SO 链接
如何通过 IIS7 发送电子邮件?