2013-04-05 111 views
1

我在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); 

    } 
+0

需要更多詳細信息,SMTP_Server和它的端口的值是什麼?你通過什麼格式的用戶名? – Arran 2013-04-05 12:40:30

+0

我試過gmail和live smtp,相信我這些設置都很好,因爲它在我的本地機器上運行時會發送一封電子郵件,並且它會在雲上打印相同的憑據。 – 2013-04-05 12:43:58

回答

1

我類似的問題。該解決方案非常「奇怪」,gmail會阻止我的電子郵件,因爲你的應用程序試圖從「奇怪」的位置登錄。嘗試檢查您是否收到gmail中的通知/電子郵件,並提供有關區塊登錄的信息。

+0

是的,就是這樣,我用sendGrid代替它,它工作。 – 2013-04-05 12:45:39

0

解決此問題的一種方法是將RDP添加到Azure虛擬機上,然後從該帳戶登錄到您的Gmail帳戶。 Google會要求您確認您的帳戶,因爲它是一個「奇怪」的位置。 一旦驗證您的電子郵件將正常工作。

相關問題