【发布时间】:2015-04-08 18:18:37
【问题描述】:
我们有一个尝试通过 SMTP 发送邮件的 Azure 托管网站。
我得到的只是超时,这是我的 POP 和 IMAP 设置以及代码。在网站下的 Azure 门户中 - 我需要在 Azure 网站设置中配置任何内容吗?
下面是我的 c# 代码...该代码使用从数据库中获取的以下值:
public bool Send(string sRecipient, string sSubject, string sBody)
{
CompanyProvider obj = _db.GetCompanyProvider();
if (!obj.EmailNotifications)
return true;
MailMessage mail = new MailMessage();
mail.To.Add(sRecipient);
mail.From = new MailAddress(obj.SenderEmail);
mail.Subject = sSubject;
string Body = sBody;
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = obj.SMTPHost;
smtp.Port = obj.SMTPPort;
smtp.Timeout = 8;
smtp.UseDefaultCredentials = false;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential(obj.SenderEmail, obj.SenderEmailPassword);// Enter senders User name and password
//smtp.Credentials = new System.Net.NetworkCredential
//(obj.SenderEmail.Substring(0, obj.SenderEmail.IndexOf('@')), obj.SenderEmailPassword);// Enter senders User name and password
try
{
smtp.Send(mail);
return true;
}
catch (Exception ex)
{
_db.writeToErrorLog(ex.ToString(), "Unable to send mail at this time");
return false;
}
}
}
【问题讨论】:
-
你能提供完整的例外吗?
标签: asp.net-mvc azure