Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.net sendmail smtp错误_Vb.net_Email_Smtp_Visual Studio 2003 - Fatal编程技术网

VB.net sendmail smtp错误

VB.net sendmail smtp错误,vb.net,email,smtp,visual-studio-2003,Vb.net,Email,Smtp,Visual Studio 2003,我使用以下代码从我的vb.net web应用程序发送电子邮件 Public Function SendMail(ByVal strTo As String, ByVal strFrom As String, _ ByVal strSubject As String, ByVal strBody As String) As String Try Dim SmtpServer As New SmtpCl

我使用以下代码从我的vb.net web应用程序发送电子邮件

Public Function SendMail(ByVal strTo As String, ByVal strFrom As String, _
                            ByVal strSubject As String, ByVal strBody As String) As String
        Try

            Dim SmtpServer As New SmtpClient()
            Dim mail As New MailMessage()
            SmtpServer.Credentials = New _
            Net.NetworkCredential("ns1.jasmine.arvixe.com", "<password>")
            SmtpServer.Port = 587
            SmtpServer.Host = "mail.<mydomain>.com"
            mail = New MailMessage()
            mail.From = New MailAddress(strFrom)
            mail.To.Add(strTo)
            mail.Subject = strSubject
            mail.IsBodyHtml = True
            mail.Body = strBody
            SmtpServer.Send(mail)
            Return True
        Catch ex As Exception
            Return False
        End Try
    End Function
公共函数SendMail(ByVal strTo作为字符串,ByVal strFrom作为字符串_
ByVal strSubject作为字符串,ByVal strBody作为字符串)
尝试
Dim SmtpServer作为新的SmtpClient()
将邮件设置为新邮件消息()
SmtpServer.Credentials=New_
Net.NetworkCredential(“ns1.jasmine.arvixe.com,”)
SmtpServer.Port=587
SmtpServer.Host=“mail..com”
mail=新邮件消息()
mail.From=新邮件地址(strFrom)
mail.To.Add(strTo)
mail.Subject=strSubject
mail.IsBodyHtml=True
mail.Body=strBody
SmtpServer.Send(邮件)
返回真值
特例
返回错误
结束尝试
端函数
当我使用我的个人live.co.uk电子邮件地址作为strFrom值,甚至是一个虚构的电子邮件地址时,它可以正常工作。但是当我用另一个的时候(contact@mydomain.com),这是完全有效和有效的,我得到以下错误:

“SMTP服务器需要安全连接,或者客户端未经身份验证。服务器响应为:需要SMTP身份验证。”


为什么会发生这种情况

查看规范RFC 2554后(http://www.faqs.org/rfcs/rfc2554.html)我的猜测是,接收/转发服务器正在采用某种身份验证方案,以确保电子邮件实际上来自strFrom指示的任何位置(服务器上的有效帐户在@之后指示)

该规范的第5项“邮件发件人命令的AUTH参数”特别令人感兴趣


由于“AUTH参数to the MAIL FROM command”并没有在任何地方使用,因此它可以解释为什么某些电子邮件地址可以使用,而其他地址则不能使用

如果将mail.From设置为“test@.com“?旁注:捕获和忽略异常被认为是非常糟糕的设计。抛出异常是有原因的。一般来说,人们至少应该记录它们。