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