从Azure网站发送电子邮件,只有超时,用完了想法

时间:2015-02-09 03:45:53

标签: asp.net-mvc azure

我们有一个Azure托管网站,它试图通过SMTP发送邮件。

我得到的只是超时,这是我的POP和IMAP设置,后跟代码。在网站下的Azure门户中 - 我是否需要在Azure网站设置中配置任何内容?

POP and IMAP settings from Office365 site

我的c#代码如下......代码使用从数据库中提取的以下值:

enter image description here

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;
        }

}

}

1 个答案:

答案 0 :(得分:0)