gpt4 book ai didi

asp.net/vb.net - system.net smtp 邮件不工作

转载 作者:太空宇宙 更新时间:2023-11-03 14:04:23 26 4
gpt4 key购买 nike

所以我有一个最近停止工作的 smtp 邮件设置。

发生的情况是代码从另一个域上的 iframe 运行。但 iframe 与 smtp 电子邮件位于同一域中。

例如:

Main Site --> www.mysite.com
Iframe --> www.myiframe.com

在 iframe 服务器上,smtp 是使用 system.net 设置的,并且直到最近才有效。 smtp 服务器在 office365 上与 goddady 一起使用,代码如下所示:

 <system.net>
<mailSettings>
<smtp from="me@mysite.com" deliveryMethod="Network">
<network host="smtp.office365.com" userName="me@mysite.com" password="password" defaultCredentials="true" port="587" enableSsl="true" />
</smtp>
</mailSettings>
</system.net>

我注意到,我最近不得不将我所有的电子邮件从 SSL 更改为 TLS,以便它们在 587 上工作。我还在我的 php 服务器上测试了这些 smtp 设置,它们工作正常,但有一个关键区别.我必须使用 SSL 定义 TLS 而不是 SSL 我收到失败的身份验证响应。

我认为可能会发生的情况是,虽然 enablessl 已启用并且应该也支持 TLS,但它不会打扰 TLS,只是进入 SSL 并失败,仅此而已。

有没有人知道在 system.net 中强制使用 TLS 的方法或者可能是最近错误的原因。

根据评论要求:

 Private Sub SendEmail()
Try
Dim smtp As New SmtpClient()
Dim Recipient As String = Request("e").ToString()
Dim name As String = Request("n").ToString()
Dim body As String = File.ReadAllText(ConfigurationManager.AppSettings("DataRoot") & "email.txt").Replace("[firstname]", name)
Dim msg As New MailMessage()
msg.From = New MailAddress(ConfigurationManager.AppSettings("ConfirmEmailFrom"), ConfigurationManager.AppSettings("ConfirmEmailFromName"))
msg.To.Add(New MailAddress(Recipient, name))
msg.Subject = ConfigurationManager.AppSettings("ConfirmEmailSubject")
msg.Body = body
smtp.Send(msg)
Catch ex As Exception
siteMessage.LogMessage("Failed sending confirmation email to " & Request("e").ToString(), ex, Nothing)
End Try
End Sub

最佳答案

System.Net 中,您可以执行 TLS 版本,如下所示 (C#):

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12

但这取决于您的应用程序使用的基础 .NET 框架版本。 .NET 4.5 及更高版本 提供对 TLS v1.2 的支持。

这里是 MSDN 文档:ServicePointManager.SecurityProtocol Property

SmtpClient 类中,除了您已经通过配置启用的 EnableSsl 属性外,没有任何其他内容。

关于asp.net/vb.net - system.net smtp 邮件不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45282820/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com