我在Windows Azure應用程序上有一個smtp客戶端,客戶端在模擬器上正常工作,但在雲實例。System.Net.Mail.SmtpException:SMTP服務器需要安全連接,或者客戶端未在Azure上進行身份驗證
異常消息是:
The SMTP server requires a secure connection or the client was not authenticated The server's response was 5.5.1 authentication required
我確信的憑據是通過在命令行打印他們的雲是正確的,我還禁用了防火牆。
P.S:我使用gmail smtp服務器。
這裏是我的代碼:
private void SetupClient()
{
_emailSetting = new EmailSetting();
_smtpClient = new SmtpClient(_emailSetting.SMTP_Server, _emailSetting.Port);
_smtpClient.EnableSsl = true;
_smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;
_smtpClient.Credentials = new NetworkCredential(_emailSetting.EmailUser, _emailSetting.EmailPass);
}
public void Report(String msg)
{
MailMessage mailMessage;
if (_smtpClient == null)
{
SetupClient();
}
String receivers = String.Join(",", Receivers);
mailMessage = new MailMessage(_emailSetting.EmailUser, receivers, "Error", msg);
_smtpClient.Send(mailMessage);
}
需要更多詳細信息,SMTP_Server和它的端口的值是什麼?你通過什麼格式的用戶名? – Arran 2013-04-05 12:40:30
我試過gmail和live smtp,相信我這些設置都很好,因爲它在我的本地機器上運行時會發送一封電子郵件,並且它會在雲上打印相同的憑據。 – 2013-04-05 12:43:58