As we send a auto generated mail to user. through our code. let us consider receiver emailid is of Gmail. then receiver have enable to receive a mail from those mails send from system i.e system or code generated. if they do not have set allow to it then mail sending is failure. How to avoid this. what should I do to send mail without rejected by client/user mail server.

I have tried:

Hide Copy Code

using (MailMessage mm = new MailMessage("trial@gmail.com", trialEmail.Text)) { mm.Subject = "Send test"; string body = "Hello " ; mm.Body = body; mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.EnableSsl = true; NetworkCredential NetworkCred = new NetworkCredential("trial@gmail.com", "password"); smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Port = 587; smtp.Send(mm); }

Google Account Security

Under the "Access for less secure apps" section, you can enable access to your account from other devices/applications... like your C# application.

Note, there is no longer an "application specific" section.

once I do this setting in receiver mail account then I able to send mail. but problem is it is by default block/off . and most of user don't make it on. bit it was surprising we got a mails from amazon or facebook sites without enabling this setting. What they do for it?

Related posts

Recent Viewed