Click here to Skip to main content
15,669,440 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, Iam preparing a small interview email project in VS2015-Asp.net with c#. But the same project works well in Windows Forms.
But when I try to send from WebForms its' giving error like

" The SMTP server requires a secure connection or the client has not authenticated. The server response was 5.5.1 authentication required"

My Codes :-

C#
try
{ 
    System.Net.Mail.MailMessage Mail = new System.Net.Mail.MailMessage();
    System.Net.Mail.SmtpClient SmtpServer = new System.Net.Mail.SmtpClient("smtp.gmail.com");
    Mail.From = new System.Net.Mail.MailAddress("paramu@gmail.com");
    Mail.To.Add(new System.Net.Mail.MailAddress(this.DropDownList1.SelectedItem.Text));
    if (TextBox1.Text.Trim().Length > 0)
    {
        Mail.Bcc.Add(this.TextBox1.Text);
    }
    if (TextBox2.Text.Trim().Length > 0)
    {
        Mail.CC.Add(this.TextBox2.Text);
    }
    Mail.Subject = this.TextBox3.Text;
    if (MyInput1.PostedFile.FileName.Trim().Length>0)
    {
        System.Net.Mail.Attachment My_Attach = new System.Net.Mail.Attachment(MyInput1.PostedFile.FileName);
        Mail.Attachments.Add(My_Attach);
    }
string MyImgString64 = "/9j/4AAQSkZJRgABAQEAYABgAAD/2wBD....";
Byte[] bitmapData = Convert.FromBase64String(FixBase64ForImage(MyImgString64));
System.IO.MemoryStream streamBitmap = new System.IO.MemoryStream(bitmapData);

System.Net.Mail.LinkedResource imageToInline = new System.Net.Mail.LinkedResource(streamBitmap, System.Net.Mime.MediaTypeNames.Image.Jpeg);
imageToInline.ContentId = "MyImage";
System.Net.Mail.AlternateView av1 = System.Net.Mail.AlternateView.CreateAlternateViewFromString("<html><body><img src=cid:MyImage/><br></body></html>" + TextBox4.Text, null, System.Net.Mime.MediaTypeNames.Text.Html);
av1.LinkedResources.Add(imageToInline);
Mail.AlternateViews.Add(av1);
Mail.IsBodyHtml = true;

Mail.BodyEncoding = System.Text.Encoding.UTF8;
SmtpServer.Port = 587;
SmtpServer.Credentials = new System.Net.NetworkCredential("paramu@gmail.com", "123456");
SmtpServer.EnableSsl = true;
SmtpServer.Send(Mail);
MessageBox.Show(this, "Sending Mail Status -> Success....!!!");
}
catch (Exception ex) {
   MessageBox.Show(this, ex.Message);  
}

Thanks Again

What I have tried:

Sending emails from asp.net web forms
Posted
Updated 11-Aug-17 2:04am
v2
Comments
F-ES Sitecore 11-Aug-17 4:15am    
This question is asked every day, please do basic research like using google before you ask a question, this is thoroughly documented.

1 solution

Quote:
I am preparing a small interview email project

If this is a job interview assessment, then the only advice that I can give you is that others have experienced the same problem. Use Google Search and you will find helpful information on there. I always start with the error message: the SMTP server requires a secure connection or the client has not authenticate - Google Search[^]
 
Share this answer
 
Comments
Paramu1973 11-Aug-17 2:26am    
Graeme Iam doing google search for past 2 days. I can't get and then I post here to get advice. Thanks for your advice.
Graeme_Grant 11-Aug-17 2:32am    
Please re-read what I have posted. There is a Google Search link in there with what looks like answers to me.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900