Click here to Skip to main content
15,909,737 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Thank you,
How to send mail from .net application using gmail smtp,
I have tried different ways but unable to send mails.
If i use another smtp other than gmail smtp from oter smtp we are able to send mails.
Thanks & Regards
Lakshman
9052026114

What I have tried:

tring SMTPUser = "example.gmail.com", SMTPPassword = "password";

//Now instantiate a new instance of MailMessage
MailMessage mail = new MailMessage();

//set the sender address of the mail message
mail.From = new MailAddress(SMTPUser, "AspnetO");

//set the recepient addresses of the mail message
mail.To.Add(ToEmail);

//set the subject of the mail message
mail.Subject = Subject;

//set the body of the mail message
mail.Body = Body;

//leave as it is even if you are not sending HTML message
mail.IsBodyHtml = true;

//set the priority of the mail message to normal
mail.Priority = MailPriority.Normal;

//instantiate a new instance of SmtpClient
SmtpClient smtp = new SmtpClient();
smtp.Port = 587; //or you can also use port# 587
/
//if you are using secure authentication using SSL/TLS then "true" else "false"
smtp.EnableSsl = true;

smtp.Send(mail);
Posted
Updated 11-Feb-16 23:41pm
v3

This is the most frequently asked question, please do basic research before posting. Usually the issue is not your code but the fact that you haven't set your account to allow other apps to use it;

Allowing less secure apps to access your account - Accounts Help[^]

Or gmail has disabled your account until you manually pass a captcha.

Either way the ultimate solution is to not send email through gmail, see point 6

Things you shouldn't spend time doing | The ASP.NET Forums[^]
 
Share this answer
 
First thing you need to remember is, you should keep enable your mail for POP settings in your Gmail account.
then collect following things
1. Receiver Email address
2. Sender Email: UserID and Password
3. Namespace System.Net.Mail
4. Email Attachment if any
check below link
Send Email from your Gmail Account using ASP.NET[^]
There are many things that can failed your email sending like,
There are so many factor that may affects your email sending code, here is list,
1. Firewall block port 587 (This is port for smtp gmail server)
2. Internet connection is not available on machine or internet connection has face some obstacles while pinging
3. Due to some typo mistake UserName and password may be get wrong
4. Enable SSL is block email sending
5. POP settings for smtp server in your Gmail account is disabled
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900