PDA

View Full Version : پیام خطا هنگام ارسال ایمیل



rahil_2008
چهارشنبه 09 تیر 1389, 00:24 صبح
سلام دوستان
من این کدو برای ارسال ایمیل نوشتم:


protectedvoid btnSendEmail_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
try
{
MailMessage mm = newMailMessage();
string str = Server.MapPath("~/Banners");
string strpath = str + @"\Banner1.jpg";
Attachment at = newAttachment(strpath );
mm.Attachments.Add(at);
mm.Body = txtBody.Text ;
mm.BodyEncoding = System.Text.Encoding.UTF8;
mm.DeliveryNotificationOptions = DeliveryNotificationOptions.Never;
MailAddress ma=null;
ma=newMailAddress("a@gmail.com","r h" ,System.Text.Encoding.UTF8);
mm.From = ma;
mm.IsBodyHtml = true;
mm.Priority = MailPriority.Normal;
mm.ReplyTo = ma;
mm.Sender = ma;
mm.Subject = txtSubject.Text ;
mm.SubjectEncoding = System.Text.Encoding.UTF8;
ma = newMailAddress(txtEmail.Text.Trim(), txtFullName.Text.Trim(), System.Text.Encoding.UTF8);
mm.To.Add(ma);
System.Net.Mail.SmtpClient smtp = newSmtpClient();
smtp.EnableSsl = true;
smtp.Timeout = 100000;
smtp.Send(mm);
}
catch (Exception ex)
{
Response.Write("Error: "+ex.Message );
}
}
}

و در web.config هم اینا رو نوشتم:


<system.net>
<mailSettings>
<smtpdeliveryMethod="Network"from="a@gmail.com">
<networkdefaultCredentials="false"host="smtp.gmail.com"password="123456"port="587"userName="a@gmail.com"/ (a@gmail.com"><networkdefaultCredentials="false"host="smtp.gmail.com"password="123456"port="587"userName="a@gmail.com"/)>
</smtp>
</mailSettings>
</system.net>

باید جواب بده اما نمی دونم چرا با این پیام خطا مواجه می شم:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required
لطفا راهنمایی کنید

rahil_2008
یک شنبه 13 تیر 1389, 12:57 عصر
کسی نمی دونه؟

ricky22
یک شنبه 13 تیر 1389, 13:29 عصر
از اتصال امن (SSL باید استفاده کنید
این (http://www.aspcode.net/Send-mail-from-ASPNET-using-your-gmail-account.aspx)نمونه کمکنون می کنه.