2015-02-09 22 views
0

我們有一個嘗試通過SMTP發送郵件的Azure託管網站。從Azure網站發送電子郵件,只有超時,用完想法

我得到的是超時,這裏是我的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; 
     } 

} 

}

+0

你能提供完整的例外嗎? – 2015-02-10 01:27:48

回答