bmanmike39
asked on
How do i send email through gmail in asp.net C#
I'm trying to send email from my asp.net page, but keep receiving the same error:
Below is the code in button to send the message:
Thanks
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
Below is the code in button to send the message:
using System.Net.Mail;
MailMessage mail = new MailMessage();
mail.From = new MailAddress("myname@gmail.com");
mail.To.Add("recientEmail@gmail.com");
mail.IsBodyHtml = true;
mail.Subject = "Email Sent";
mail.Body = "Body content from";
SmtpClient smtp = new SmtpClient();
smtp.Credentials = new System.Net.NetworkCredential("myname@gmail.com", "mypassword", "smtp.gmail.com");
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Send(mail);
Thanks
465 is the SSL port (your mentioned port uses TLS)
ASKER
First thank you. But i tried port 465 and it times out
Error:
The operation has timed out.
Error:
The operation has timed out.
okay return to 587 please. Now try again, but with
ABOVE the line where you have the credentials.
smtp.UseDefaultCredentials = false;
ABOVE the line where you have the credentials.
ASKER
I get the following error:
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank You! I don't know whet the difference was but it worked. Your code had a "sender" and the credentials where configured different.