Murray Brown
asked on
VB.net Windows Forms Failure Sending Mail SMTP Exception
I am getting the following error "Failure Sending Mail: SMTP Exception" in the following code
Private Sub btnSendNetMail_Click(sende r As System.Object, e As Microsoft.Office.Tools.Rib bon.Ribbon ControlEve ntArgs) Handles btnSendNetMail.Click
SendNetMail("murbro9@yahoo .com", "murbro9@yahoo.com", "Test Subject", "", "")
End Sub
Public Sub SendNetMail(ByVal MsgFrom As String, ByVal MsgTo As String, ByVal MsgSubject As String, ByVal MsgBody As String, ByVal oAttachment As String)
Try
' Pass in the message information to a new MailMessage
Dim msg As New Net.Mail.MailMessage(MsgFr om, MsgTo, MsgSubject, MsgBody)
If oAttachment = "" Then
'Do nothing
Else
msg.Attachments.Add(New System.Net.Mail.Attachment (oAttachme nt))
End If
' Set the format of the mail message body as HTML
msg.IsBodyHtml = True
' Set the priority of the mail message to normal
msg.Priority = MailPriority.Normal
' Create an SmtpClient to send the e-mail
' Dim mailClient As New SmtpClient("105.236.251.36 ") ' = local machine IP Address
Dim mailClient As New SmtpClient(GetIPAddress) ' = local machine IP Address
' Use the Windows credentials of the current User
mailClient.UseDefaultCrede ntials = True
' Pass the message to the mail server
mailClient.Send(msg)
' Optional user reassurance:
'MsgBox(String.Format("Mes sage Subject ' {0} ' successfully sent From {1} To {2}", MsgSubject, MsgFrom, MsgTo), "EMail", Windows.Forms.MessageBoxBu ttons.OK)
' Housekeeping
msg.Dispose()
Catch ex As FormatException
MsgBox(ex.Message & " :Format Exception")
Catch ex As SmtpException
MsgBox(ex.Message & " :SMTP Exception")
End Try
End Sub
Private Function GetIPAddress() As String
Try
Dim strHostName As String
Dim strIPAddress As String
strHostName = System.Net.Dns.GetHostName ()
strIPAddress = System.Net.Dns.GetHostByNa me(strHost Name).Addr essList(0) .ToString( )
GetIPAddress = strIPAddress
Catch
MsgBox(Err.Description & " abc4")
End Try
'
End Function
Private Sub btnSendNetMail_Click(sende
SendNetMail("murbro9@yahoo
End Sub
Public Sub SendNetMail(ByVal MsgFrom As String, ByVal MsgTo As String, ByVal MsgSubject As String, ByVal MsgBody As String, ByVal oAttachment As String)
Try
' Pass in the message information to a new MailMessage
Dim msg As New Net.Mail.MailMessage(MsgFr
If oAttachment = "" Then
'Do nothing
Else
msg.Attachments.Add(New System.Net.Mail.Attachment
End If
' Set the format of the mail message body as HTML
msg.IsBodyHtml = True
' Set the priority of the mail message to normal
msg.Priority = MailPriority.Normal
' Create an SmtpClient to send the e-mail
' Dim mailClient As New SmtpClient("105.236.251.36
Dim mailClient As New SmtpClient(GetIPAddress) ' = local machine IP Address
' Use the Windows credentials of the current User
mailClient.UseDefaultCrede
' Pass the message to the mail server
mailClient.Send(msg)
' Optional user reassurance:
'MsgBox(String.Format("Mes
' Housekeeping
msg.Dispose()
Catch ex As FormatException
MsgBox(ex.Message & " :Format Exception")
Catch ex As SmtpException
MsgBox(ex.Message & " :SMTP Exception")
End Try
End Sub
Private Function GetIPAddress() As String
Try
Dim strHostName As String
Dim strIPAddress As String
strHostName = System.Net.Dns.GetHostName
strIPAddress = System.Net.Dns.GetHostByNa
GetIPAddress = strIPAddress
Catch
MsgBox(Err.Description & " abc4")
End Try
'
End Function
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER