What's new

Need Help Sending Mail

  • Thread starter Genetic Paradox
  • Start date
  • Views 432
G

Genetic Paradox

Enthusiast
Messages
411
Reaction score
61
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("[email protected]")
MyMailMessage.To.Add("[email protected]")
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("[email protected]", "DICKSEVERYWHERE")
SMTP.Send(MyMailMessage)
 
Ibdc

Ibdc

VIP
VIP
Retired
Forum Addict MotM
Messages
4,969
Reaction score
2,193
Don't use a try catch for the whole thing, only the actual sending.
 
J

James Iz A Pro

Enthusiast
Messages
69
Reaction score
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("[email protected]")
MyMailMessage.To.Add("[email protected]")
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("[email protected]", "Password")
SMTPServer.EnableSsl = True
Try
SMTPServer.Send(MyMailMessage)
Catch ex As SmtpException
End Try
End If
 
G

Genetic Paradox

Enthusiast
Messages
411
Reaction score
61
I got it working. Thank you both very much.
 
Top Bottom