I am trying to make my asp.net web form send an email from @gmail.com to @gmail.com email address. Using code provided below. Obviously, "username@gmail.com" is replaced with the email address that sends an email and etc.
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Try Dim SmtpServer As New SmtpClient() Dim mail As New MailMessage() SmtpServer.Credentials = New _ Net.NetworkCredential("username@gmail.com", "password") SmtpServer.Port = 587 SmtpServer.Host = "smtp.gmail.com" mail = New MailMessage() mail.From = New MailAddress("yourusername@gmail.com") mail.To.Add("recieveraddress") mail.Subject = "Test Mail" mail.Body = "This is for testing SMTP mail from GMAIL" SmtpServer.Send(mail) MsgBox("mail send") Catch ex As Exception MsgBox(ex.ToString) End Try End Sub
When the button is pressed, I receive the error message:
How can I fix it? Thanks!
ASP.NETEmail ServersVisual Basic.NET
Last Comment
JServicesLLC
8/22/2022 - Mon
Salah Eddine ELMRABET
Hi,
It seem this is authentication problem! have you correctly define the password? also the port you use : 587 is not working I tried a telnet to google SMTP using this port without success.
Basically you can use default smtp port 25 or 465 (secured port).
Best regards.
Salah
JServicesLLC
Have you followed the following steps?
Enable IMAP in your Gmail settings
Sign in to Gmail.
Click the gear in the top right .
Select Settings.
Click Forwarding and POP/IMAP.
Select Enable IMAP.
Click Save Changes.
I have some code laying around somewhere that I have used to send email with gmail if you need it. Just let me know. It's in VB.NET
EDIT:
Also you are passing the password instead of "password" correct?
German Mikulski
ASKER
Hi,
I have tried to use ports your offered, but none of them worked - -25 gave the same error, and 465 was just loading for 15 minutes and did nothing eventually.
Yes, IMAP was enables.
Hm, pretty sure password is right, I have tried two different email addresses, none works. When I type password in, does it look like "********"? Do In need any additional ''?.. Just in case
And yes, I would like to see your code if you don't mind explaining in breif how it works)
I will find it. I have to finish up a small project and then I will see what I can do.
Salah Eddine ELMRABET
Hi,
Do you use texbox type password in the form?? the "*********" you see is it in the web page display when you fill the form or when you edit the script??
try to use plain text texbox and see if you can send the email, if this is the case try to find what happened within you code in the script
regards.
Salah
JServicesLLC
I found it. I am modifying to as I have a whole bunch of application specific items in it. I will post it here in a few minutes.
It seem this is authentication problem! have you correctly define the password? also the port you use : 587 is not working I tried a telnet to google SMTP using this port without success.
Basically you can use default smtp port 25 or 465 (secured port).
Best regards.
Salah