?
Solved

VB.net Windows Forms Failure Sending Mail SMTP Exception

Posted on 2014-04-14
2
Medium Priority
?
1,468 Views
Last Modified: 2014-04-17
I am getting the following error "Failure Sending Mail: SMTP Exception" in the following code

    Private Sub btnSendNetMail_Click(sender As System.Object, e As Microsoft.Office.Tools.Ribbon.RibbonControlEventArgs) 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(MsgFrom, MsgTo, MsgSubject, MsgBody)

            If oAttachment = "" Then
                'Do nothing
            Else
                msg.Attachments.Add(New System.Net.Mail.Attachment(oAttachment))
            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.UseDefaultCredentials = True



            ' Pass the message to the mail server

            mailClient.Send(msg)

            '  Optional user reassurance:

            'MsgBox(String.Format("Message Subject ' {0} ' successfully sent From {1} To {2}", MsgSubject, MsgFrom, MsgTo), "EMail", Windows.Forms.MessageBoxButtons.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.GetHostByName(strHostName).AddressList(0).ToString()
            GetIPAddress = strIPAddress
        Catch
            MsgBox(Err.Description & " abc4")
        End Try

        '
    End Function
0
Comment
Question by:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 2000 total points
ID: 40001538
Do you have an SMTP installed and running on the machine where the code is executing? If not, you'll need one, or you'll need to point it at a server that does have one.
0
 

Author Closing Comment

by:Murray Brown
ID: 40006179
thanks for the help
0

Featured Post

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question