I want to send email from my Visual basic form
my code:
Private Sub email1()
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("MYEMAIL#gmail.com", "MYPASS")
Smtp_Server.Port = 465
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.gmail.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress("MYEMAIL#gmail.com")
e_mail.To.Add("MYFRIENDEMAIL#gmail.com")
e_mail.Subject = "SUBJECT"
e_mail.IsBodyHtml = False
e_mail.Body = "TEXT MESSAGE"
Smtp_Server.Send(e_mail)
Catch error_t As Exception
email_status.Text = ("Error: " & error_t.Message)
MsgBox(error_t.Message)
Exit Sub
End Try
email_status.Text = ("OK")
End Sub
errors while using smtp.gmail.com
while using SMTP port 465: The operation has timed out.
while using SMTP port 587: Failure sending email.
while using SMTP port 25: Failure sending email.
errors while using smtp.googlemail.com
while using SMTP port 465: The operation has timed out.
while using SMTP port 587: Failure sending email.
while using SMTP port 25: Failure sending email.
i am using AVAST antivirus but i turned it off
can you please help me?
thank you very much.
Related
I have tried different port numbers but I keep getting the error message and no email sent. I aim to be able to send the email successfully and the message will contain details from an appointment booked. Any help please?
Dim UserName As String = "example#gmail.com"
Dim mail As MailMessage = New MailMessage
mail.From = New MailAddress(UserName)
mail.To.Add(New MailAddress(txtEmailAddress.Text))
mail.Subject = "Appointment Details"
mail.Body = "Test message"
mail.IsBodyHtml = True
Dim client As SmtpClient = New SmtpClient("smtp.gmail.com", 465)
client.EnableSsl = True
client.Credentials = New System.Net.NetworkCredential(UserName, "***")
Try
client.Send(mail)
Catch ex As Exception
MessageBox.Show("Sending email failed. Please Try again")
End Try
What you need to do is add client.UseDefaultCredentials = False, but make sure you set it to false before calling client.Credentials = New System.Net.NetworkCredential(UserName, "***")
Also, for GMail, you need to use port 587 which is the port that supports the STARTTLS extension (which is the only way that System.Net.Mail.SmtpClient supports SSL).
In other words, change your code to this:
Dim UserName As String = "example#gmail.com"
Dim mail As MailMessage = New MailMessage
mail.From = New MailAddress(UserName)
mail.To.Add(New MailAddress(txtEmailAddress.Text))
mail.Subject = "Appointment Details"
mail.Body = "Test message"
mail.IsBodyHtml = True
Dim client As SmtpClient = New SmtpClient("smtp.gmail.com", 587)
client.EnableSsl = True
client.UseDefaultCredentials = False
client.Credentials = New System.Net.NetworkCredential(UserName, "***")
Try
client.Send(mail)
Catch ex As Exception
MessageBox.Show("Sending email failed. Please Try again")
End Try
Try this,
go to your gmail account (www.gmail.com)
login, and check that you have "enabled Pop for all mail".
you can find this under the tab "Forwarding and POP/IMAP"
Also try switching the port number to 587
Dim mail As New Net.Mail.MailMessage()
mail.From = New Net.Mail.MailAddress("abc#xyz.com")
mail.[To].Add("abc#xyz.com")
mail.IsBodyHtml = True
mail.Subject = "A subject line."
mail.Body = "A mail body message."
Dim smtp As New Net.Mail.SmtpClient("smtp.xyz.com", 25)
smtp.Credentials = New System.Net.NetworkCredential("abc#xyz.com","password")
Try
smtp.Send(mail)
MsgBox("Your Email has been sent sucessfully - Thank You")
Catch exc As Exception
MsgBox("Send failure: " & exc.ToString())
End Try
In Windows Application a simple SMTP using Credential, throwing Exception-
Failure sending mail.
Why it is throwing can anybody help me out.
Dim MESSAGE As New MailMessage()
MESSAGE.From = New MailAddress(Mail_From)
MESSAGE.BodyEncoding = System.Text.Encoding.UTF8
MESSAGE.To.Add(email)
MESSAGE.Subject = "Testing"
MESSAGE.BodyEncoding = System.Text.Encoding.UTF8
MESSAGE.Body = msg
Dim smtp As New SmtpClient()
smtp.Host = SMTP_Host
smtp.Port = SMTP_Port
smtp.UseDefaultCredentials = False
smtp.Credentials = New System.Net.NetworkCredential(Mail_User, Mail_PW)
smtp.EnableSsl = False
smtp.Send(MESSAGE)
i got error:
MAIL Error Message:Mailbox unavailable. The server response was:
This email has identified as high probability of being a spam mail
by our
The mail has been rejected by the server, there is nothing you can do to resolve this. You could in theory attempt to modify the content so that is does not appear as spammy, but this is likely to be a long and tedious process.
this is my code it was running without errors but suddenly
an exception appears
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
Dim smtpserver As New SmtpClient()
Dim mail As New MailMessage()
smtpserver.Credentials = New Net.NetworkCredential("myemail#gmail.com", "mypass")
smtpserver.Host = "smtp.gmail.com"
smtpserver.Port = "587"
mail = New MailMessage
mail.From = New MailAddress("myHouseHQ#gmail.com")
mail.To.Add(Form2.TextBox1.Text)
mail.Subject = "EagleEyes"
mail.Body = "EagleEyes has detected a movement!"
If emailphoto Then
Dim attach As New Attachment("D:\hi" & sm & ".jpg")
mail.Attachments.Add(attach)
End If
smtpserver.EnableSsl = True
smtpserver.UseDefaultCredentials = False
' Try1
smtpserver.Send(mail)
'Catch ex As SmtpException
'MsgBox("Error Connection!" & ex.Message)
'End Try
sm += 1
Don't use "" by the port.
Please try this for the port:
smtpserver.Port = 587
Here's my code (yes I censored my email/password) (when you click button)
Dim Mail As New MailMessage
Mail.Subject = "test email"
Mail.To.Add("*****")
Mail.From = New MailAddress("*****") '
Mail.Body = "This is an email!"
Dim SMTP As New SmtpClient("smtp.gmail.com")
SMTP.EnableSsl = True
SMTP.Credentials = New System.Net.NetworkCredential("*****", "*****")
SMTP.Port = 587
SMTP.Send(Mail)
MsgBox("Sent Successfully")
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at (link which doesn't help)
SOLVED!
I never would have guessed.
Google wasn't letting me use my account because it was hacked. It apparently was hacked when I was writing code...
FYI, a safer version would be
Using mail As MailMessage = New MailMessage
mail.Subject = "test email"
mail.To.Add("*****")
mail.From = New MailAddress("*****") '
mail.Body = "This is an email!"
Using smtp As New SmtpClient("smtp.gmail.com")
smtp.EnableSsl = True
smtp.Credentials = New System.Net.NetworkCredential("*****", "*****")
smtp.Port = 587
smtp.Send(mail)
End Using
End Using
MsgBox("Sent Successfully")
This would ensure that the mail and smtp objects get cleaned up, whether or not an exception occurs.