System.Net.Mail.SmtpException:发送邮件失败 - SMTP问题

时间:2016-07-25 10:44:55

标签: .net email smtp

情景1: 通过使用适当的主机在网站上提交电子邮件表单发送邮件(telnet在端口25正常工作)在我们的本地系统(代码绝对相同)上工作正常,因为我们发送的次数(无论连续提交之间的时间间隔是多少) 。我们在提交表单时会在提到的电子邮件地址中收到回复。

情景2: 但是当我们在服务器上提交表单时,它会第一次成功发送邮件,我们会将响应返回给使用的邮件地址。 当我们尝试第二次提交表格时,如果在2分30秒的间隙(已经过验证但不确定配置的位置)之前尝试它会失败,如果我们尝试在2分钟后提交表格,则会成功秒。

在服务器上,这是我们得到的日志:

System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: 
Unable to connect to the remote server ---> System.Net.Sockets.SocketException: 

  A connection attempt failed because the connected party did not 
  properly respond after a period of time, or established connection 
  failed because connected host has failed to respond <SMTP server IP>:25

at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress 
socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure,
Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, 
IAsyncResult asyncResult, Exception& exception)
--- End of inner exception stack trace ---
at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean 
async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6)
at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate 
asyncCallback)
at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate 
asyncCallback, Int32 creationTimeout)
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpClient.Send(MailMessage message)
--- End of inner exception stack trace ---

任何人都可以解释哪里出错了?

非常感谢!

1 个答案:

答案 0 :(得分:0)

好的,所以这里有一个问题: 我的实例托管在AWS中,Amazon Elastic Compute Cloud(Amazon EC2)默认通过端口25限制电子邮件流量。

要避免从EC2通过SMTP端点发送电子邮件时出现超时,请使用其他端口(587或2587)。或者我们需要填写一份请求到亚马逊以删除电子邮件发送限制以消除限制。

更多信息:https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-connect.html