问题描述
您好我有一个可以使用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)
结束尝试
任何帮助将不胜感激。
谢谢
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
这篇关于使用SMTP发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!