SmtpClient.发送异常
我的网站发送购买确认电子邮件。 95% 的情况下,它是有效的。单击运行付款并应发送电子邮件的“确认”按钮后的另外 5%,我收到以下异常:
详细信息:
异常:发送邮件失败。
内部异常:无法连接到 远程服务器
内部异常 (2):连接尝试失败 因为关联方没有 一段时间后正确应对 时间,或建立的连接失败 因为连接的主机未能 回复72.167.234.197:25
发送电子邮件的代码是这样的:
Dim smtpClientPayPalSuccess As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
smtpClientPayPalSuccess.Host = "relay-hosting.secureserver.net"
smtpClientPayPalSuccess.Send(mailMessagePayPalSuccess)
仅供参考:我已向托管确认我不需要任何凭据,也不需要不同于 25 的端口号。这也是通过 https 运行的。
知道为什么这种情况只在一小部分时间发生吗?
谢谢。
戴夫
My site sends confirmation emails from a purchase. 95% of the time, it works. The other 5% after clicking the 'Confirm' button that runs the payment and should send the email, i get the following exception:
Details:
Exception: Failure sending mail.
Inner Exception: Unable to connect to
the remote server
Inner Exception
(2): 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 72.167.234.197:25
The code to send the email is this:
Dim smtpClientPayPalSuccess As System.Net.Mail.SmtpClient = New System.Net.Mail.SmtpClient()
smtpClientPayPalSuccess.Host = "relay-hosting.secureserver.net"
smtpClientPayPalSuccess.Send(mailMessagePayPalSuccess)
FYI: I have confirmed with the hosting that I don't need any credentials, or a different port number than 25. This is also running over https.
Any idea why this would be happening only a small percentage of the time?
Thanks.
Dave
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道为什么邮件有时会失败。据我所知,可能是对防火墙或邮件服务器本身进行定期维护。
我建议您异步发送邮件,而不是作为“确认”按钮过程的一部分。只需将邮件放在(持久)存储中,并在中间间隔一段时间继续尝试发送即可。
或者(强烈推荐)是将邮件从您的应用发送到本地邮件服务器,并让该邮件服务器将邮件转发到
72.167.234.197:25
。这样您就可以免费重试,并且向localhost
发送邮件失败的机会非常小(或者应该很小)。I don't know why the mail fails part of the time. As far as I know it could be scheduled maintenance of the firewalls or the mail server itself.
I would advise you to send the mail asynchronously, and not as part of the 'Confirm' button process. Just put the mail on a (persistent) store and keep trying to send it with some time in between.
Alternatively (and heartily recommended) is to send the mail from your app to a local mail server, and let that mail server forward the mail to
72.167.234.197:25
. That way you get the retries for free and the chance that sending mail tolocalhost
fails is quite small (or it should be small).根据您的说明,很可能存在实际的网络错误,导致您的站点无法与 SMTP 服务器连接/通信。这可能是由于流量过多或网络连接速度慢造成的。我的建议是对电子邮件代码进行尝试/捕获,并且可能在放弃之前重试发送电子邮件几次。
当您提到此方法在 95% 的情况下都有效时,这表明问题很可能超出您的控制范围。
附带说明一下,您也许应该考虑不要放弃 SMTP 服务器的实际 IP 地址(这对问题没有影响)
It is possible and quite likely based on your exposition, that there are actual network errors that prevent your site from connecting/communicating with the SMTP server. This could be the result of too much traffic, or maybe slow network connections. My recommendation would be to put a try/catch around the emailing code, and maybe retry sending the e-mail a few times before giving up.
When you mention that this is working 95% of the time it shows that the problem most likely lies outside of your control.
As a side note, you should maybe consider not giving up the actual IP address of your SMTP server (it is of no consequence to the question)