使用SMTP发送电子邮件 [英] Sending Email Using SMTP

查看:437
本文介绍了使用SMTP发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我有一个可以使用smtp发送电子邮件的程序。我试过使用smtp.gmail.com作为服务器主机,我的程序完全正常工作。但是当我尝试使用来自mandrillapp.com的smtp,即smtp.mandrillapp.com时,我遇到了一个错误,上面写着Relay Access Denied。这里有人想帮我解决这个问题吗?

我已经有了这个代码:





尝试

Dim SmtpServer作为新的SmtpClient()

Dim mail As New MailMessage()



如果txtFrom。 Text =或者txtBody.Text =或者txtPwd.Text =或者txtSubject.Text =或者txtTo.Text =然后

MsgBox(正确填充数据)

退出Sub

结束如果



'SMTP服务器设置。

SmtpServer。凭证=新Net.NetworkCredential(txtFrom.Text,txtPwd.Text)

SmtpServer.Port = 587

SmtpServer.Host =smtp.mandrillapp.com



'验证来自EMailID的代码

Dim emailExpression As New Regex(^ [_ a-z0-9 - ] +(。[a- z0-9 - ] +)@ [a-z0-9 - ] +(。[a-z0-9 - ] +)*(。[az] {2,4})$)

如果不是emailExpression.IsMatch(txtFrom.Text)那么

MsgBox(电子邮件ID不正确,MsgBoxStyle.Exclamation,验证电子邮件ID)

txtFrom。焦点()

退出Sub

结束如果



mail = New MailMessage()

mail.From =新邮件地址(txtFrom.Text)



'代码添加收据电子邮件ID



Dim Toaddr As String = txtTo.Text

Dim i As Integer

尝试

For i = 0 To Toaddr.Length - 1

如果不是emailExpression.IsMatch(Toaddr)那么

MsgBox(电子邮件ID不正确,MsgBoxStyle.Exclamation,验证电子邮件ID)

txtTo.Focus()

退出Sub

结束如果

mail.To.Add(Toaddr)

下一页

Catch ex As Exception

结束尝试



尝试

Dim Attach()As String = txtAttachements.Text.Split(,)

尝试

For i = 0 To Attach.Length - 2

Dim atach作为新附件(Attach(i))

mail.Attachments.Add(atach)

下一页

Catch ex As Exception

结束尝试

Catch ex As Exception

结束尝试

mail.Subject = txtSubject.Text

mail.Body = txtBody.Text

SmtpServer.EnableSsl = True

SmtpServer.Send(邮件)

MsgBox(邮件发送成功,MsgBoxStyle.Information)

Catch ex As Exception

MsgBox(ex.ToString)

结束尝试



任何帮助将不胜感激。

谢谢

解决方案



如果不是emailExpression.IsMatch(txtFrom.Text)那么

MsgBox(电子邮件ID不正确,MsgBoxStyle.Exclamation,验证电子邮件ID)

txtFrom.Focus()

退出子

结束如果



mail = New MailMessage()

mail.From = New MailAddress(txtFrom.Text )



'添加收据的代码电子邮件ID



Dim Toaddr As String = txtTo.Text

Dim i As Integer

尝试

For i = 0 To Toaddr.Length - 1

如果不是emailExpression.IsMatch (Toaddr)然后

MsgBox(电子邮件ID不正确,MsgBoxStyle.Exclamation,验证电子邮件ID)

txtTo.Focus()

退出子级

结束如果

mail.To.Add(Toaddr)

下一页

Catch ex As Exception

结束尝试



尝试

Dim Attach()As String = txtAttachements.Text.Split(,)

尝试

For i = 0 To Attach.Length - 2

Dim atach As New Attachment(Attach(i))

mail.Attachments .Add(atach)

下一页

Catch ex As Exception

结束尝试

Catch ex As Exception

结束尝试

mail.Subject = txtSubject.T分机

mail.Body = txtBody.Text

SmtpServer.EnableSsl = True

SmtpServer.Send(mail)

MsgBox(Mail send Successfully,MsgBoxStyle.Information)

Catch ex As Exception

MsgBox(ex.ToString)

结束尝试



非常感谢任何帮助。

谢谢


拒绝中继访问意味着你'尝试使用他们的服务器使用他们网络之外的代码发送电子邮件。现在配置服务器的方式意味着您不能将该服务器与您的应用程序一起使用。



唯一可以帮助您解决此问题的人是拥有该服务器的人您尝试使用的服务器。我们无法帮助您,因为我们没有该服务器的管理员权限。



您的代码无法改变这种情况。

Hi i have a program that can send email using smtp. I've tried to use smtp.gmail.com as the server host and my program totally work. But When I try to use smtp from mandrillapp.com which is smtp.mandrillapp.com I've got an error that says "Relay Access Denied". Is anyone here would like to help me in this problem?
I have already this code:


Try
Dim SmtpServer As New SmtpClient()
Dim mail As New MailMessage()

If txtFrom.Text = "" Or txtBody.Text = "" Or txtPwd.Text = "" Or txtSubject.Text = "" Or txtTo.Text = "" Then
MsgBox("Fill Data Correctly")
Exit Sub
End If

' SMTP server setting .
SmtpServer.Credentials = New Net.NetworkCredential(txtFrom.Text, txtPwd.Text)
SmtpServer.Port = 587
SmtpServer.Host = "smtp.mandrillapp.com"

' Code To Validate The from EMailID
Dim emailExpression As New Regex("^[_a-z0-9-]+(.[a-z0-9-]+)@[a-z0-9-]+(.[a-z0-9-]+)*(.[a-z]{2,4})$")
If Not emailExpression.IsMatch(txtFrom.Text) Then
MsgBox("EMail Id is Not Correct", MsgBoxStyle.Exclamation, "Validation for EMail ID")
txtFrom.Focus()
Exit Sub
End If

mail = New MailMessage()
mail.From = New MailAddress(txtFrom.Text)

' Code To Add Receipants EMail ID's

Dim Toaddr As String = txtTo.Text
Dim i As Integer
Try
For i = 0 To Toaddr.Length - 1
If Not emailExpression.IsMatch(Toaddr) Then
MsgBox("EMail Id is Not Correct", MsgBoxStyle.Exclamation, "Validation for EMail ID")
txtTo.Focus()
Exit Sub
End If
mail.To.Add(Toaddr)
Next
Catch ex As Exception
End Try

Try
Dim Attach() As String = txtAttachements.Text.Split(",")
Try
For i = 0 To Attach.Length - 2
Dim atach As New Attachment(Attach(i))
mail.Attachments.Add(atach)
Next
Catch ex As Exception
End Try
Catch ex As Exception
End Try
mail.Subject = txtSubject.Text
mail.Body = txtBody.Text
SmtpServer.EnableSsl = True
SmtpServer.Send(mail)
MsgBox("Mail send Successfully ", MsgBoxStyle.Information)
Catch ex As Exception
MsgBox(ex.ToString)
End Try

Any help would be greatly appreciated.
Thanks

解决方案

")
If Not emailExpression.IsMatch(txtFrom.Text) Then
MsgBox("EMail Id is Not Correct", MsgBoxStyle.Exclamation, "Validation for EMail ID")
txtFrom.Focus()
Exit Sub
End If

mail = New MailMessage()
mail.From = New MailAddress(txtFrom.Text)

' Code To Add Receipants EMail ID's

Dim Toaddr As String = txtTo.Text
Dim i As Integer
Try
For i = 0 To Toaddr.Length - 1
If Not emailExpression.IsMatch(Toaddr) Then
MsgBox("EMail Id is Not Correct", MsgBoxStyle.Exclamation, "Validation for EMail ID")
txtTo.Focus()
Exit Sub
End If
mail.To.Add(Toaddr)
Next
Catch ex As Exception
End Try

Try
Dim Attach() As String = txtAttachements.Text.Split(",")
Try
For i = 0 To Attach.Length - 2
Dim atach As New Attachment(Attach(i))
mail.Attachments.Add(atach)
Next
Catch ex As Exception
End Try
Catch ex As Exception
End Try
mail.Subject = txtSubject.Text
mail.Body = txtBody.Text
SmtpServer.EnableSsl = True
SmtpServer.Send(mail)
MsgBox("Mail send Successfully ", MsgBoxStyle.Information)
Catch ex As Exception
MsgBox(ex.ToString)
End Try

Any help would be greatly appreciated.
Thanks


"Relay access denied" means that you're trying to use their server to send an email using code outside of their network. The way the server is configured right now means that you cannot use that server with your application.

The only people who can help you with this problem are the people who own the server you're trying to use. We can't help you with this because we don't have admin access to that server.

There is nothing you can do in your code to change this situation.


这篇关于使用SMTP发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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