2017-07-24 69 views
0

所以我有一个最近停止工作的smtp邮件设置。asp.net/vb.net - system.net smtp邮件不能正常工作

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

例如:

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

在IFRAME服务器的SMTP是使用system.net设置和工作,直到最近。 SMTP服务器是goddady上office365的代码如下所示:

<system.net> 
    <mailSettings> 
     <smtp from="[email protected]" deliveryMethod="Network"> 
     <network host="smtp.office365.com" userName="[email protected]" 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的方法,或者可能是最近bug的原因。

作为经由意见要求:

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 
+0

你能分享你的代码吗?你已经分享了配置部分。 –

+0

@KaushalKumarPanday完成 – dim

回答

1

System.Net可以强制TLS版本如下所示(C#):

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 

然而,这是依赖于底层您的应用程序正在使用的.NET Framework版本。支持TLS v1.2可在.NET 4.5及以上版本

下面是该MSDN文档:ServicePointManager.SecurityProtocol Property

SmtpClient类没有从中你已经通过配置使EnableSsl财产没有分开。