如何使用vb.net发送SMTP电子邮件 - 错误5.7.1无法中继 [英] How to send SMTP email using vb.net - error 5.7.1 Unable to relay

查看:168
本文介绍了如何使用vb.net发送SMTP电子邮件 - 错误5.7.1无法中继的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过我们的公司交换服务器使用vb.net 2008发送电子邮件,我收到以下消息。 邮箱不可用。服务器响应为:5.7.1无法中继MyEmailAdrress@MyDomain.com。电子邮件地址是我的公司域,并且登录凭据是我的域名。我没有尝试在域外发送电子邮件,因此我不理解RELAY部分。



谢谢。



Ed



尝试
'创建一个新的MailMessage对象并指定From和To地址
Dim message As New MailMessage(MyEmailAdrress@MyDomain.com,MyEmailAdrress@MyDomain.com,Subject HERE,Body message HERE)
Dim emailClient As New SmtpClient(MySMTPServer。 MyDomain.local)
'认证
Dim basicAuthenticationInfo As New System.Net.NetworkCredential(MyNetworkUSERID,MyNetworkUSERPASSWORD,MyDomain)
emailClient.UseDefaultCredentials = False
emailClient.Credentials = basicAuthenticationInfo
message.IsBodyHtml = True
emailClient.Send(message)
Catch ex As Exception
Debug.Print(ex.Message)
结束尝试



以下是OUTPUT

邮箱不可用。服务器响应为: 5  7  1 无法  relay   MyEmailAdrress@MyDomain.com 

解决方案

尝试使用此代码进行必要的更改。





 Private Sub Button1_Click(发件人作为对象,e作为EventArgs)处理Button1.Click 
尝试
Dim Smtp_Server作为新SmtpClient
Dim e_mail作为新MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential(username@gmail.com,password)
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host =smtp.gmail.com//替换为您的域名主机名。

e_mail = New MailMessage()
e_mail.From = New MailAddress(txtFrom.Text)
e_mail.To.Add(txtTo.Text)
e_mail.Subject =电子邮件发送
e_mail.IsBodyHtml = False
e_mail.Body = txtMessage.Text
Smtp_Server.Send(e_mail)
MsgBox(发送邮件)

Catch error_t As Exception
MsgBox(error_t.ToString)
结束尝试

结束子


< blockquote> 答案!!



我的开发笔记本电脑的IP地址是否已添加到服务器上的ALLOW RELAY列表中。 - 这解决了这个问题。当我将其部署到生产服务器上时,我还必须添加服务器IP地址。



感谢mgoad99 http:/ /www.codeproject.com/script/Membership/View.aspx?mid=3894223 [ ^ ]



更新的VB代码不再需要用户名,密码或域名

  Dim  MailFrom  As  System.Net.Mail.MailAddress 
Dim MailTo As System.Net.Mail.MailAddress
Dim MailSubject 作为 字符串
Dim MailBody As String
Dim Mail As New MailMessage
Dim MailClient As SmtpClient

MailBody = 测试电子邮件
MailSubject = < span class =code-string> 测试主题
' 这里我不关心来自电子邮件地址,它是一个虚拟电子邮件组成
MailFrom = MailAddress( DUMMY-Email-Here@SomePlace.com
MailTo = MailAddress( JDoe@SomePlace.com

Mail.From = MailFrom
Mail。 To .Add(MailTo)
Mail。 Subject = MailSubject
Mail.Body = MailBody

25是SMTP主机的端口
MailClient = SmtpClient( MySMTPServer.someplace.local 25

尝试
MailClient.Send(Mail)
Catch ex As 异常
Debug.Print( 邮件错误:& ex.Message)
结束 尝试


I am trying to send an email using vb.net 2008 via our corporate exchange server and I am receiving the following message. Mailbox unavailable. The server response was: 5.7.1 Unable to relay for MyEmailAdrress@MyDomain.com. The email addresses are mine for the corporate domain, and the login credentials are mine for the domain. I have not tried to send email outside of the domain thus i don't understand the RELAY part.

Thanks.

Ed

Try
       ' Create a new MailMessage object and specify the "From" and "To" addresses
       Dim message As New MailMessage("MyEmailAdrress@MyDomain.com", "MyEmailAdrress@MyDomain.com", "Subject HERE", "Body message HERE")
       Dim emailClient As New SmtpClient("MySMTPServer.MyDomain.local")
       ' Authentication
       Dim basicAuthenticationInfo As New System.Net.NetworkCredential("MyNetworkUSERID", "MyNetworkUSERPASSWORD", "MyDomain")
       emailClient.UseDefaultCredentials = False
       emailClient.Credentials = basicAuthenticationInfo
       message.IsBodyHtml = True
       emailClient.Send(message)
   Catch ex As Exception
       Debug.Print(ex.Message)
   End Try


Below is the OUTPUT

Mailbox unavailable. The server response was: 5.7.1 Unable to relay for MyEmailAdrress@MyDomain.com

解决方案

Try this code making necessary changes.


Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
      Try
          Dim Smtp_Server As New SmtpClient
          Dim e_mail As New MailMessage()
          Smtp_Server.UseDefaultCredentials = False
          Smtp_Server.Credentials = New Net.NetworkCredential("username@gmail.com", "password")
          Smtp_Server.Port = 587
          Smtp_Server.EnableSsl = True
          Smtp_Server.Host = "smtp.gmail.com" //Replace with your domain host name.

          e_mail = New MailMessage()
          e_mail.From = New MailAddress(txtFrom.Text)
          e_mail.To.Add(txtTo.Text)
          e_mail.Subject = "Email Sending"
          e_mail.IsBodyHtml = False
          e_mail.Body = txtMessage.Text
          Smtp_Server.Send(e_mail)
          MsgBox("Mail Sent")

      Catch error_t As Exception
          MsgBox(error_t.ToString)
      End Try

   End Sub


ANSWER!!

Had my development laptop's IP address added to the ALLOW RELAY list on the server. -- This resolved the problem. When I deploy this onto a production server I will have to get the servers IP address added also.

Thanks to mgoad99 http://www.codeproject.com/script/Membership/View.aspx?mid=3894223[^]

UPDATED VB CODE NO LONGER REQUIRES USER NAME, PASSWORD or DOMAIN

 Dim MailFrom As System.Net.Mail.MailAddress
 Dim MailTo As System.Net.Mail.MailAddress
 Dim MailSubject As String
 Dim MailBody As String
 Dim Mail As New MailMessage
 Dim MailClient As SmtpClient

 MailBody = "Test Email"
 MailSubject = "Test Subject"
'Here I do not care about the from Email address, it is a Dummy-Email made up
 MailFrom = New MailAddress("DUMMY-Email-Here@SomePlace.com")
 MailTo = New MailAddress("JDoe@SomePlace.com")

 Mail.From = MailFrom
 Mail.To.Add(MailTo)
 Mail.Subject = MailSubject
 Mail.Body = MailBody

'25 is the port of the SMTP host
 MailClient = New SmtpClient("MySMTPServer.someplace.local", 25) 

 Try
     MailClient.Send(Mail)
 Catch ex As Exception
     Debug.Print("Mail Error: " & ex.Message)
 End Try


这篇关于如何使用vb.net发送SMTP电子邮件 - 错误5.7.1无法中继的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆