I am trying to sent email from my web application (an e-commerce site). i enabled "Less secure app access" from my mail account. And enabled IMAP
also from mail setting. but still sending email is blocked or failed. What can be the possible reason for this? or i missing something in the code section?
here is code:
var client = new SmtpClient("smtp.gmail.com", 587)
{
EnableSsl = true,
Credentials = new NetworkCredential(userName, password)
};
var sender = new MailAddress(senderEmail, senderName);
var receiver = new MailAddress(receiverEmail);
var message = new MailMessage(@sender, receiver);
IIRC then I followed this guidance to enable gmail smtp for my application.
two factor authentication
for the account.then you use it as
MailMessage mm = new MailMessage();
mm.From = new MailAddress(<your-gmail>);
mm.To.Add(address);
mm.Subject = subject;
mm.Body = body;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new NetworkCredential(<your-gmail>, <app-password>);
smtp.Send(mm);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.