Need Help Sending Mail

Discussion in 'Programming & Scripting' started by Genetic Paradox, Jul 25, 2009 with 3 replies and 364 views.

  1. Genetic Paradox

    Genetic Paradox Enthusiast

    Messages:
    422
    Ratings:
    60
    This code should work just fine but when I'm debugging it but it gives me this error every time I try to send the message"A first chance exception of type 'System.Net.Mail.SmtpException' occurred in System.dll". There is no elaboration on the error. That is all I get.
    Code:
    Dim MyMailMessage As New MailMessage()
    Try
    MyMailMessage.From = New MailAddress("LeeroyDatJenkins@gmail.com")
    MyMailMessage.To.Add("Rheejus@gmail.com")
    MyMailMessage.Subject = "Rabid Rabi"
    MyMailMessage.Body = TextBox3.Text + TextBox4.Text
    Dim SMTP As New SmtpClient("smtp.gmail.com")
    SMTP.Port = 486
    SMTP.EnableSsl = True
    SMTP.Credentials = New System.Net.NetworkCredential("LeeroyDatJenkins@gmail.com", "DICKSEVERYWHERE")
    SMTP.Send(MyMailMessage)


     
  2. Ibdc

    Ibdc Retired Retired

    Messages:
    5,100
    Ratings:
    2,072
    Don't use a try catch for the whole thing, only the actual sending.
     
    • Like Like x 1
  3. James Iz A Pro

    James Iz A Pro Enthusiast

    Messages:
    62
    Ratings:
    2
    Try This Code
    Code:
    Declarations:
    Imports System.Net.Mail
    
    The Send Button Code:
    
    Dim WC As New System.Net.WebClient
    Dim MyMailMessage As New MailMessage
    MyMailMessage.From = New MailAddress("LeeroyDatJenkins@gmail.com")
    MyMailMessage.To.Add("Rheejus@gmail.com")
    MyMailMessage.Subject = "Rabid Rabi"
    WC.Dispose()
    MyMailMessage.Body = TextBox3.Text + TextBox4.Text
    Dim SMTPServer As New SmtpClient("smtp.gmail.com")
    SMTPServer.Port = 587
    SMTPServer.Credentials = New System.Net.NetworkCredential("LeeroyDatJenkins@gmail.com", "Password")
    SMTPServer.EnableSsl = True
    Try
    SMTPServer.Send(MyMailMessage)
    Catch ex As SmtpException
    End Try
    End If
    
     
    • Like Like x 1
  4. OP
    Genetic Paradox

    Genetic Paradox Enthusiast

    Messages:
    422
    Ratings:
    60
    I got it working. Thank you both very much.
     

Share This Page