我们有一个Azure托管网站,它试图通过SMTP发送邮件。
我得到的只是超时,这是我的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;
}
}
}
答案 0 :(得分:0)