VB.NET GMAIL SMTP Server Settings - vb.net

I am using the Following Code for my GMAIL Server SMTP Settings, but am unable to send emails.
Can anyone help me out...
Dim emailClient As New SmtpClient("mail.gmail.com")
Dim SMTPUserInfo As New System.Net.NetworkCredential("xxxxx#gmail.com", "abc123")
emailClient.UseDefaultCredentials = False
emailClient.Port = 465
emailClient.EnableSsl = True
emailClient.Credentials = SMTPUserInfo
emailClient.Timeout = 1000000
emailClient.Send(mail)
emailClient = Nothing
SMTPUserInfo = Nothing
Catch ex As Exception
MessageBox.Show(ex.Message & " Error Mails : ", Me.Text, MessageBoxButtons.OK)
End Try

I think, you should use following settings:
emailClient.Host = "smtp.gmail.com"
emailClient.port = 587
emailClient.EnableSsl = True

If you connect using SMTP, you can only send mail to Gmail or Google Apps users; if you connect using SSL/TLS, you can send mail to anyone. If your device or application supports SSL - connect to smtp.gmail.com on port 465. To connect with SSL, you need to provide a Google username and password for authentication.
Source: https://support.google.com/a/answer/176600?hl=en

Related

STMP Authentication Required

It's work before, but suddenly there was this problem last month. Without changing the code
In my issue is when i trying to send the email with SmtpClient In VB.net .It's throw exception error message as
System.Net.Mail.SmtpException: The SMTP server requires a secure
connection or the client was not authenticated. The server response
was: 5.7.0 Authentication Required.
Whether I use app password / less secure app access also with same error!
Code of below :
Using client As New SmtpClient(AccountOption.AccMailSMTP, AccountOption.AccMailPort) 'SMTP: smtp.gmail.com & Port: 587
message = New MailMessage(ParamEmail, fileReaderEmail) 'From Email & To Email
Dim rich As New RichEditControl
Dim test As New MemoryStream(AccountOption.AccMailDefaultContent)
rich.LoadDocument(test, DocumentFormat.Html)
message.Attachments.Add(New Attachment(file))
message.Subject = subject.Name & " For " & IO.Path.GetFileName(debtorFolder)
message.IsBodyHtml = True
message.Body = rich.HtmlText
client.UseDefaultCredentials = True
client.Credentials = New Net.NetworkCredential(ParamEmail, ParamPassword) 'To Email & The Password / App Password
client.DeliveryMethod = SmtpDeliveryMethod.Network
client.Timeout = 10000
client.EnableSsl = True
Try
client.Send(message)
Catch ex As Exception
Throw ex
End Try
End Using
The Link i have tried . But it same:
How do I send an email with Gmail and SmtpClient when the sending account uses two factor authentication?
The server response was: 5.7.0 Authentication Required. Learn more at
hi go to your google account in the security panel
Click on turn off/on access (recommend)
in the opened panel it must be turned on

Web hosting from smarterasp.net. the mail is not sended it shows SMTP server requires a secure connection

When I used this code to send mail on the visual studio 2012 server (localhost), the mail has been sent successfully. But it shows an authentication problem when I'm free web hosting from smarterasp.net.What problem is going on?
Private Sub sendCode()
'email verify
Dim Random As Random = New Random()
activationCode = Random.Next(1001, 9999).ToString()
Session("activationCode") = activationCode
'email sending
Dim smtp As SmtpClient = New SmtpClient()
smtp.Host = "smtp.gmail.com"
smtp.Port = 587
smtp.EnableSsl = True
smtp.UseDefaultCredentials = False
smtp.Credentials = New NetworkCredential("xyz#xyz.com", "xxxxxxx")
Dim msg As MailMessage = New MailMessage("xyz#xyz.com", Session("toEmail"), "Activation Code to verify Email Address", "Dear, Alumni your Activation Code is " + activationCode + "\n\n\nThanks & Regards\nVidyasagar University CS Students")
Try
smtp.Send(msg)
lblMessage.Text = "Mail sent successfully"
Session("isFromCheck") = "yes"
Response.Redirect("emailVerification.aspx")
Catch ex As Exception
lblMessage.Text = ex.Message
End Try
End Sub
I expect the mail sending should be successful as on my development server
but it shows me ------->
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
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Net.Mail.SmtpException: 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
Source Error:
Line 90: Line 91: Line 92: smtp.Send(msg) Line
93: Session("isFromCheck") = "yes"
Source File:
h:\root\home\subhankarjana-001\www\alumnifeedback\check.aspx.vb
Line: 92

How to test SMTP connection before SMTPClient.Send [VB.NET]

Pretty new to programming here.
The program I'm currently working on needs to send an email with logs.
Working great if I'm using the right server host but when I'm trying with a "false" server host my program sure can't connect, but it immediatly crash, I can't raise any exception, can't tell the user he's doing something wrong, nothing.
So I guess I have to test the connection before SMTPClient.Send but I can't seem to find how...
How can I test a SMTP Server connection in VB.NET ?
That's what I'm using :
Try
Dim SmtpServer As New SmtpClient()
With SmtpServer
.EnableSsl = False
.UseDefaultCredentials = False
.Credentials = New Net.NetworkCredential(MailUser, MailPassword)
.Port = 25
.Host = ServerAdress
End With
Dim mail As New MailMessage()
With mail
.From = New MailAddress(MailSender)
.To.Add(MailReceiver)
.CC.Add(MailCC)
.Subject = MailObject
.Body = MailBody
End With
SmtpServer.Send(mail)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
1- I think you should try something like this:
Using tcp As New TcpClient
Try
tcp.Connect(ip, 25)
' server found
Catch ex As Exception
' server not found
End Try
tcp.Close()
End Using ' tcpclient
2- For test your smtp server this article can be usefull:
https://www.port25.com/how-to-check-an-smtp-connection-with-a-manual-telnet-session-2/
3- and also there is a smtp test class in this question's answers
.Net TcpClient and SmtpClient won't connect to my Smtp server

Email Service works just fine locally but it doesn't work when the site is deployed to godaddy host

I have a function that sends email in my website. My website is written in Visual Basic and my email sender function is below:
Dim mail As New MailMessage()
mail.Subject = Trim(TextBox1.Text())
mail.Body = Trim(TextBox2.Text())
Try
Dim SmtpServer As New SmtpClient()
SmtpServer.Host = "smtpout.secureserver.net"
SmtpServer.Port = 80
SmtpServer.Credentials = New Net.NetworkCredential("test#test.org", "password")
mail.From = New MailAddress("admin#test.org")
mail.To.Add("customer#test.org")
mail.CC.Add(Trim(HiddenField1.Value()))
mail.Subject = Trim(TextBox1.Text())
mail.Body = Trim(TextBox2.Text())
mail.IsBodyHtml = True
SmtpServer.Send(mail)
Response.Redirect("Welcome.aspx", False)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
The email function and everything worked just fine on my local dev machine. But they never worked when I deployed to the windows hosting in GoDaddy.
Here is what I get as an exception:
I know that GoDaddy has some strict rules for sending emails. But to avoid this, I couldn't find good documentation. What am I missing?
The host name is probably not the right one.
SmtpServer.Host = "smtpout.secureserver.net"
Godaddy mentions this as a blanket host for most of the SMTP related requests. But, they have actually implemented a system where each user is given a sandboxed access to its SMTP service. The combination of hostname and port is used to uniquely identify the user.
You could find this in your settings, their terminology is email relay server.
Reference:
Godaddy

SSL Error with sending an email in VB

Here is the code I have to send the email:
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Try
Dim SmtpServer As New SmtpClient
SmtpServer.EnableSsl = True
Dim mail As New MailMessage
SmtpServer.Credentials = New Net.NetworkCredential("Frrizzeh#gmail.com", "Password here")
SmtpServer.Port = "587"
SmtpServer.Host = "smtp.gmail.com"
mail = New MailMessage
mail.From = New MailAddress("Frrizzeh#gmail.com")
mail.To.Add("Frrizzeh#gmail.com")
mail.Subject = TextBox1.Text
mail.Body = TextBox2.Text
SmtpServer.Send(mail)
Catch ex As Exception
MsgBox(ex.Message)
End Try
However when I run the program it just returns this error:
The SMTP server requires a secure connection or the client was not authenticated.
The server server response was: 5.5.1 Authentication required.
Any ideas where I am going wrong?
Try enabling less secure password from: https://www.google.com/settings/security/lesssecureapps so you can login from your app.
Also, try adding the following properties
SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network
SmtpServer.UseDefaultCredentials = False
You might have two step verification enabled and if so you need to generate an app specific password for you to use. Ive answered this and provided code in another question like this before. See link below...
Fail Sending Email Unable To Connect the Remote Server
I had this problem and fixed it by changing my gmail password to a stronger one with upper, lower, symbol, numeric.
It was funny that it worked fine from localhost but failed from my server.