2017-09-29 48 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