locked
Visual Studio 2012 SmtpExpection Problem RRS feed

  • Question

  • How To Fix SmtpExpection was Unhandled Please Answer,I HOPE YOU ANSWER ALL THANK YOU
    Thursday, January 4, 2018 10:22 AM

All replies

  • With really zero information to go by how do you expect us to assist you?

    So I would suggest to report back the unhandled exception. You can do this by one of two ways, wrap the code that is causing the exception with a try/catch statement, in the catch place either Console.WriteLine(ex.Message) which will write to either the IDE intermediate window or output window (you need to open them from the ide view menu) or subscribe to SendCompleted event as per the following which you will need to setup for your settings in regards to mail server address etc. Same as the try/catch, get the error message and report back to us.

    Public Sub SendAsync()
        'create the mail message
        Dim mail As New MailMessage()
    
        'set the addresses
        mail.From = New MailAddress("me@mycompany.com")
        mail.To.Add("you@yourcompany.com")
    
        'set the content
        mail.Subject = "This is an email"
        mail.Body = "this is the body content of the email."
    
        'send the message
        Dim smtp As New SmtpClient("127.0.0.1") 'specify the mail server address
        'the userstate can be any object. The object can be accessed in the callback method
        'in this example, we will just use the MailMessage object.
        Dim userState As Object = mail
    
        'wire up the event for when the Async send is completed
        AddHandler smtp.SendCompleted, AddressOf SmtpClient_OnCompleted
    
        smtp.SendAsync(mail, userState)
    End Sub
    
    Public Sub SmtpClient_OnCompleted(ByVal sender As Object, ByVal e As AsyncCompletedEventArgs)
        'Get the Original MailMessage object
        Dim mail As MailMessage = CType(e.UserState, MailMessage)
    
        'write out the subject
        Dim subject As String = mail.Subject
    
        If e.Cancelled Then
            Console.WriteLine("Send canceled for mail with subject [{0}].", subject)
        End If
        If Not (e.Error Is Nothing) Then
            Console.WriteLine("Error {1} occurred when sending mail [{0}] ", subject, e.Error.ToString())
        Else
            Console.WriteLine("Message [{0}] sent.", subject)
        End If
    End Sub
    


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, January 4, 2018 11:42 AM
  • How To Fix SmtpExpection was Unhandled Please Answer,I HOPE YOU ANSWER ALL THANK YOU

    You got a SMTP error doing what?
    Thursday, January 4, 2018 11:42 AM
  • How To Fix SmtpExpection was Unhandled Please Answer,I HOPE YOU ANSWER ALL THANK YOU
    Can have endless reason, the most simple one, your server host does not allow you to use SMTP.

    Success Cor

    Thursday, January 4, 2018 11:53 AM
  • Please post the exception (error message) trace so that we can help.

    Paul ~~~~ Microsoft MVP (Visual Basic)

    Thursday, January 4, 2018 2:08 PM