I am trying to test sending out an e-mail from vb.net. I am sending an e-mail from mygmail account to myself, however I keep getting an error message: 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("smtp.gmail.com", 587)
SmtpServer.EnableSsl = True
SmtpServer.Credentials = New Net.NetworkCredential("MYEMAILADDRESS", "MYPASSWORD")
Dim mail As New MailMessage("MYEMAILADDRESS", "MYEMAILADDRESS", "This is my Title", "This is my Email")
SmtpServer.Send(mail)
I have read a few post but all of them say change the port. I have changed the port however it doesn't seem to work. If I change the port it gives a similar error.
Related
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
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
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
I am working on a VB application that sends an HTML email. I found this, and am trying to implement it.
'create the mail message
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress(EmailFrom, "Display Name")
mail.To.Add(EmailTo)
'set the content
mail.Subject = "Subject Line"
mail.Body = "Message body"
mail.IsBodyHtml = True
'send the message
Dim smtp As New SmtpClient("127.0.0.1")
smtp.Send(mail)
I don't have any info on the argument passed to SmtpClient() for this code snippet.
I have found videos showing how to connect to google smtp using "smtp.gmail.com" and a specific port. However, This would only be practical if all of the users of my application will have Gmail. I don't want to force them to have one in order to have access to the functionality.
Could any of you experts provide me with some help on dynamically selecting the correct smtp server and port based on their email?
for example, email is stored in a variable called email:
Dim email As String = "me#gmail.com"
This email is coming from MySql database so how do I take variable string and check which ISP they use and then have my code use the correct smtp and port for that ISP?
Also, I've read that now days authentication is required so I will likely prompt user with input box before calling procedure that sends the email.
Here's some code showing that:
Hotmail:
Smtp.live.com
Port: 587
Gmail:
smtp.gmail.com
Port: 587
Yahoo:
smtp.mail.yahoo.com
Port: 465
Aol:
smtp.aol.co.uk
Port: 587
imports system.net.mail
dim Mail as new mailmessage
Try
mail.From = New MailAddress("FROM EMAIL")
mail.To.Add(TO EMAIL)
mail.Subject = "SUBJECT"
mail.Body = "BODY"
Dim s As New SmtpClient("HOST")
s.Port = PORT
s.EnableSsl = True
s.Credentials = New System.Net.NetworkCredential("FROM EMAIL, "FROM PASSWORD")
s.Send(Mail)
MsgBox("E-mail was sucsessfully sent!", MsgBoxStyle.Information, "Information")
Catch ex As Exception
End Try
I'm completely stumped. Any help would be greatly appreciated. I am also open to any ideas that accomplish same feat even if not in accordance with first code snippet. Thanks in advance.
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.