2011-09-26 36 views
13

Đây là Web.config của tôi:C# - Không thể gửi mail trong Windows Azure qua Gmail SMTP

<system.net> 
    <mailSettings> 
     <smtp deliveryMethod="Network"> 
      <network defaultCredentials="true" enableSsl="true" host="smtp.gmail.com" port="25" userName="[email protected]" password="xxxxxxxxxxx"/> 
     </smtp> 
    </mailSettings> 
</system.net> 

phương pháp của tôi:

public static void EmailVerification(string email, string nickname) 
    { 
     MailAddress from = new MailAddress("xxxxxxxxxxx", "xxxxxxxxxxxx"); 
     MailAddress to = new MailAddress(email); 

     MailMessage message = new MailMessage(from, to); 

     message.Subject = "Test"; 
     message.Body = "Test"; 
     SmtpClient client = new SmtpClient(); 

     try 
     { 
      client.Send(message); 
     } 
     catch(SmtpFailedRecipientException ex) 
     { 
      HttpContext.Current.Response.Write(ex.Message); 
      return; 
     } 
    } 

thất bại của tôi SmtpException:

Failure sending mail. 

InnerException:

Unable to connect to the remote server 

Tôi đang thử nghiệm tại địa phương nhưng tôi đoán nó sẽ hoạt động. Tôi phải chạy nó trên Windows Azure, tôi đã cố gắng và nó đã không làm việc quá. Có cái gì tôi đang mất tích?

+0

thấy câu hỏi này: http://stackoverflow.com/questions/32260/sending-email-in-net-through-gmail/32336#32336 –

Trả lời

7

Tùy chọn xác thực cơ bản và tùy chọn thông tin xác thực mạng mặc định là loại trừ lẫn nhau; nếu bạn đặt defaultCredentials thành true và chỉ định tên người dùng và mật khẩu, thông tin xác thực mạng mặc định sẽ được sử dụng và dữ liệu xác thực cơ bản sẽ bị bỏ qua.

Sử dụng

<system.net> 
    <mailSettings> 
     <smtp deliveryMethod="Network"> 
      <network enableSsl="true" host="smtp.gmail.com" port="25" userName="[email protected]" password="xxxxxxxxxxx"/> 
     </smtp> 
    </mailSettings> 
</system.net> 
+0

tôi thấy, tôi đã sử dụng như thế này : Tôi cần thay đổi cổng thành 587 –

Các vấn đề liên quan