2017-09-29 39 views
0

我試圖使用亞馬遜的服務SES發送電子郵件:AWS SES郵件服務問題:端口?超時? STARTTLS?

String username = "&&&&&&"; // Replace with your SMTP username. 
     String password = "&&&&&&&"; // Replace with your SMTP password. 
     String host = "email-smtp.us-west-2.amazonaws.com"; 
     int port = 25; 
     String senderAddress = "[email protected]"; 
     String receiverAddress = inputEmail; 

     using (var client = new System.Net.Mail.SmtpClient(host, port)) 
     { 
      client.Credentials = new System.Net.NetworkCredential(username, password); 
      client.EnableSsl = true; 

      String message = "Trucking On Demand received a request to reset the password for your account " + inputEmail + ".Your new password is: " + tempPassword; 
      client.Send 
      (
         senderAddress, // Replace with the sender address. 
         inputEmail, // Replace with the recipient address. 
         message, 
         "This email was delivered through ****." 
      ); 

     return Ok(); 
     } 
    } 

爲什麼我的請求超時?我試圖搜索互聯網,但除了要求我啓用TLS之外,aws並沒有明確的解決此問題的答案。我相信client.enablessl可以完成這項工作。我是否也需要處置我的客戶?即client.dispose();

+1

你真的只是超時,或者你得到一個真正的錯誤?您在哪個地區配置了SES賬戶? orhtej2提供的鏈接就是一個很好的例子。我會從那開始,然後向後工作到您的代碼。注意:您必須使用端口587.端口25不受支持。 –

回答

2

official documentation開始應該連接到端口587

+0

這是@Ackman的正確答案。而且,如果代碼在EC2中,則需要從運行代碼的實例中訪問Internet。 –

+0

實際上在文檔中我發現,除非您明確地將它傳遞給aws ses團隊,否則您不能將電子郵件發送給未註冊的收件人。 – Ackman