مرجع تخصصی برنامه نویسان

انجمن تخصصی برنامه نویسان فارسی زبان

کاربر سایت

alone.m2a

عضویت از 1393/08/03

خطا در ارسال ایمیل

  • سه شنبه 11 خرداد 1395
  • 12:58
تشکر میکنم

با سلام ، این کد ارسال هست

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();
        }

اما این خطا رو میده

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

 

پاسخ های این پرسش

تعداد پاسخ ها : 2 پاسخ
کاربر سایت

ایمان مدائنی

عضویت از 1392/01/20

  • سه شنبه 11 خرداد 1395
  • 13:10

به لینک زیر برید و گزینه را روی Enabme ست کنید

https://www.google.com/settings/security/lesssecureapps

کاربر سایت

mahmoodof123

عضویت از 1395/02/13

  • پنجشنبه 3 تیر 1395
  • 00:01

سلام

جواب شما اینجا ..

 
 

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

کاربرانی که از این پست تشکر کرده اند

هیچ کاربری تا کنون از این پست تشکر نکرده است

اگر نیاز به یک مشاور در زمینه طراحی سایت ، برنامه نویسی و بازاریابی الکترونیکی دارید

با ما تماس بگیرید تا در این مسیر همراهتان باشیم :)