Email not send using Gmail smtp on host - vb.net

I've used this code to sending emails. When I test this code in LOCALHOST, it works correctly, but in host, I get this error:
Failure sending mail.few
My code is:
Dim MailMsg As New MailMessage(New Net.Mail.MailAddress("MYUSERNAME#gmail.com"), New Net.Mail.MailAddress("myname#gmail.com"))
MailMsg.Subject = "test"
MailMsg.Body = "test"
MailMsg.IsBodyHtml = True
Dim SmtpMail As New Net.Mail.SmtpClient
Dim SMTPUserInfo As New Net.NetworkCredential()
SMTPUserInfo.UserName = "MYUSERNAME"
SMTPUserInfo.Password = "MYPASSWORD"
SmtpMail.UseDefaultCredentials = False
SmtpMail.Credentials = SMTPUserInfo
SmtpMail.Host = "smtp.gmail.com"
SmtpMail.Port = 587
SmtpMail.EnableSsl = True
SmtpMail.Send(MailMsg)

'Start by creating a mail message object
Dim MyMailMessage As New MailMessage()
'From requires an instance of the MailAddress type
MyMailMessage.From = New MailAddress("USERNAME#gmail.com")
'To is a collection of types
MyMailMessage.To.Add("DESTINATION#EXAMPLE.COM")
MyMailMessage.Subject = "XXXXXXX" & x
MyMailMessage.Body = "XXXXXXXXXXXXXXXXXXX "
Dim attach As New Attachment(fileName)
MyMailMessage.Attachments.Add(attach)
'Create the SMTPClient object and specify the SMTP GMail server
Dim SMTPServer As New SmtpClient("smtp.gmail.com")
SMTPServer.Port = 587
SMTPServer.Credentials = New System.Net.NetworkCredential("USERNAME#gmail.com", "PASSWD")
SMTPServer.EnableSsl = True
SMTPServer.Send(MyMailMessage)
SMTPServer.Dispose()
MyMailMessage.Dispose()

Related

The SMTP server requires a secure connection VB.NET

Dim smtp As New SmtpClient
Dim mail As New MailMessage
smtp.Credentials = New Net.NetworkCredential("mail#gmail", "password")
mail.From = New MailAddress("mail#gmail.com")
mail.To.Add(totxt.Text$)
mail.Body = bodytxt.Text
If Not ListBox1.Items.Count <= 0 Then
Dim d As Integer
Dim attach As New Attachment(ListBox1.Items(d))
mail.Attachments.Add(attach)
End If
mail.Subject = subjecttxt.Text
smtp.EnableSsl = True
smtp.Port = "587"
smtp.Host = "smtp.gmail.com"
smtp.Send(mail)
smtp.Dispose()
done.Text = "Mail sent"
PictureBox4.BackgroundImage = My.Resources.tickfnl
dtls.Visible = False
I am trying to send email from my gmail account.But i am getting the error "The SMTP Server requires a secure connection".I even enabled LESS-SECURE APP login in my account settings.The password and email address is correct.I tried another email but same issue.Any fix ?
I TRIED ALL THE SOLUTIONS FROM THE DUPLICATE LINK,STILL THE SAME PROBLEM
**IF I REMOVE THIS LINE
smtl.enablessl=true
then i get this error
the server resposnse was 5.7.0 **
Fixed the error using EASendMail
Fixed it using EASendmail :
Panel6.Visible = True
done.Text = "Sending..."
''''''''''''''''''''''''
Dim oMail As New SmtpMail("TryIt")
Dim oSmtp As New EASendMail.SmtpClient()
oMail.From = fromtxt.Text
oMail.To = New AddressCollection(totxt.Text)
oMail.Subject = subjecttxt.Text
If html.CheckAlign = True Then
oMail.HtmlBody = bodytxt.Text
Else
oMail.TextBody = bodytxt.Text
End If
Dim oServer As New SmtpServer(MailConfig.host.Text)
oServer.Port = MailConfig.port.Text
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
oServer.User = fromtxt.Text
oServer.Password = MailConfig.password.Text
Dim r As Integer
If ListBox1.Items.Count <= 0 Then
Else
oMail.AddAttachment(ListBox1.Items(r))
End If
oSmtp.LogFileName = Application.StartupPath & "\maillog.log"
Try
oSmtp.SendMail(oServer, oMail)
done.Text = "Mail sent !"
PictureBox4.BackgroundImage = My.Resources.tickfnl
Catch ex As Exception
aa = MsgBox(ex.Message)
done.Text = "Sending failed."
PictureBox4.BackgroundImage = My.Resources.excll
End Try

can't send Email from Webservice written in vb.net

I wanna send an Email from my Webservice, written in vb.net, but I get an Timeout.
What is wrong?
Dim toaddress As MailAddress = New MailAddress("xxx")
Dim fromaddress As MailAddress = New MailAddress("yyy")
' The structure for MailMessage(from, to)
Dim message As MailMessage = New MailMessage(fromaddress, toaddress)
message.Subject = "I have sent you a message from a program!"
message.Body = "Hello World!"
Dim messanger As SmtpClient = New SmtpClient("smtpxxx", 995)
messanger.Credentials = New NetworkCredential("user", "password")
messanger.EnableSsl = True
messanger.Send(message)
You are doing many things wrong and some of the information you have given are not clear enough. host name and port names have to give properly. it chooses which mail service you are using, from your code it is not correctly provided, so i will give a snippet that uses gmail to send mail. please go through this and make changes as per your SmtpHost.
Try
Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential("email", "password")
Smtp_Server.Port = 587
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.gmail.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress(txtemail.Text)
e_mail.To.Add(txtemail.Text)
e_mail.Subject = "Email Sending"
e_mail.IsBodyHtml = False
e_mail.Body = txtMessage.Text
Smtp_Server.Send(e_mail)
MsgBox("Mail Sent")
Catch error_t As Exception
MsgBox(error_t.ToString)
End Try
This link help you to find the smtp.Server and Port numbers, you can use this thread for check the limitations of smtp.servers

Send SMS via SMTP with UNICODE String vb.net

This is my code, i get only ??? chars in message body,
i tried to use property "mm.BodyEncoding = Encoding.UTF8", i also tried to add a header of "utf-8", never works for me
Dim smtp = New SmtpClient()
smtp.EnableSsl = UseSsl
smtp.Host = Host
smtp.Port = Port
smtp.Credentials = Credentials
Dim mm = New MailMessage
mm.From = New MailAddress(Credentials.UserName, ScreenName)
mm.Subject = Subject
mm.Body = "אבג"
mm.IsBodyHtml = True
mm.To.AddRange(addresses)
smtp.Send(mm)

Mailing Attempt Object Reference?

I am trying to make a simple e-mail sending program but it has confused me when it said object reference not set to an instance of an object
Try
Dim mail As MailMessage
Dim client As SmtpClient
Dim SmtpServer As New SmtpClient()
Dim fromAddress As String
Dim toAddress1 As String
Dim toAddress2 As String
Dim toAddress3 As String
Dim subject As String
Dim message As String
SmtpServer.Credentials = New Net.NetworkCredential("*********#gmail.com", "**********")
client.UseDefaultCredentials = False
fromAddress = FromEmail.Text
If ToEmail1.Visible = True Then
toAddress1 = ToEmail1.Text
ElseIf ToEmail1.Visible = True And ToEmail2.Visible = True Then
toAddress1 = ToEmail1.Text
toAddress2 = ToEmail2.Text
ElseIf ToEmail1.Visible = True And ToEmail2.Visible = True And ToEmail3.Visible = True Then
toAddress1 = ToEmail1.Text
toAddress2 = ToEmail2.Text
toAddress3 = ToEmail3.Text
End If
subject = "Subject"
Message = "Message"
mail = New MailMessage(fromAddress, toAddress1, subject, Message)
client = New SmtpClient("Smtp.live.com")
client.Port = 587
Dim SMTPUserInfo As New System.Net.NetworkCredential("user#hotmail.com", "password")
client.Credentials = SMTPUserInfo
client.Send(mail)
MsgBox("sent")
Catch ex As Exception
MsgBox(ex.Message.ToString())
End Try
you're declaring two smtpclients
Dim client As SmtpClient
Dim SmtpServer As New SmtpClient()
you instantiated SmtpServer, but not client. Then you do
client.UseDefaultCredentials = False
I guess this is where the exception is raised.
the code looks like having some lines to send some mail through SmtpServer from a google account and other lines to send some mail through client from a hotmail account. Besides, SmtpServer is using some server defined in config.sys.

Send email using smtp but operation timed out using ZOHO

Dim Smtp_Server As New SmtpClient
Dim e_mail As New MailMessage()
Smtp_Server.UseDefaultCredentials = False
Smtp_Server.Credentials = New Net.NetworkCredential(abc#zoho.com,abc123)
Smtp_Server.Port = 465
Smtp_Server.EnableSsl = True
Smtp_Server.Host = "smtp.zoho.com"
e_mail = New MailMessage()
e_mail.From = New MailAddress(abc#zoho.com)
e_mail.To.Add("david#hotmail.com")
e_mail.Subject = "Testing"
e_mail.IsBodyHtml = False
Smtp_Server.Send(e_mail)
Return True
Now I trying to send email to other person but the error show me the operation timed out, when using ZOHO to send. And I got find the solution but still fail to send. How can I solve it?
Try to use PORT : 587
Smtp_Server.Port = 587