با سلام ، این کد ارسال هست
public virtual ActionResult SendMail() { using (MailMessage mm = new MailMessage("fromaddress", "toadress")) { mm.Subject = "Account Activation"; string body = "Hello "; mm.Body = body; mm.IsBodyHtml = true; SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587); smtp.EnableSsl = true; NetworkCredential NetworkCred = new NetworkCredential("fromaddress", "frompassword"); smtp.UseDefaultCredentials = true; smtp.Credentials = NetworkCred; smtp.Send(mm); } return View(); }
اما این خطا رو میده
به لینک زیر برید و گزینه را روی Enabme ست کنید
سلام
جواب شما اینجا ..
Google may block sign in attempts from some apps or devices that do not use modern security standards. Since these apps and devices are easier to break into, blocking them helps keep your account safer.
Some examples of apps that do not support the latest security standards include:
The Mail app on your iPhone or iPad with iOS 6 or below
The Mail app on your Windows phone preceding the 8.1 release
Some Desktop mail clients like Microsoft Outlook and Mozilla Thunderbird
Therefore, you have to enable Less Secure Sign-In in your google account.
After sign into google account, go to:
https://www.google.com/settings/security/lesssecureapps
In C#, you can use the following code:
using (MailMessage mail = new MailMessage())
{
mail.From = new MailAddress("email@gmail.com");
mail.To.Add("somebody@domain.com");
mail.Subject = "Hello World";
mail.Body = "<h1>Hello</h1>";
mail.IsBodyHtml = true;
mail.Attachments.Add(new Attachment("C:\\file.zip"));
using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
{
smtp.Credentials = new NetworkCredential("email@gmail.com", "password");
smtp.EnableSsl = true;
smtp.Send(mail);
}
}
-------------------
Similar answer with screenshots http://stackoverflow.com/a/32457468/52277
هیچ کاربری تا کنون از این پست تشکر نکرده است
با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)