Click here to Skip to main content
15,880,364 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,

I just host my website and created 3 mails and configure to outlook and tested successfully incoming and outgoing mails.

now i just used my mail in coding but by coding if i sent message to my mail info@website.com from gmail it recieved message successfully but when i sent message to any gmail from my mail i cant recieve it and got error.

I used this code,

XML
MailMessage mail = new MailMessage();
     mail.To.Add("aarohi_verma@gmail.com");
     mail.From = new System.Net.Mail.MailAddress("info@mywebsitename.com");
     mail.Subject = "Testing from code..!";

     mail.IsBodyHtml = true;
     mail.Body = string.Format("<html><body><b>Dear</b>" +
     " <font> Hello THis is for just testing </font><br/><br/>" +

     "</body></html>");

     SmtpClient smtp = new SmtpClient();
     smtp.DeliveryMethod = SmtpDeliveryMethod.Network;

     smtp.Host = "smtp.gmail.com";
     smtp.Port = 587;

     smtp.UseDefaultCredentials = false;
     smtp.Credentials = new System.Net.NetworkCredential("info@mywebsitename.com", "my mail password from control panel");

     smtp.EnableSsl = true;
     smtp.Send(mail);



it gives error like:

 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
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpException: 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

Source Error:


Line 49: 
Line 50:         smtp.EnableSsl = true;
Line 51:         smtp.Send(mail);
Line 52:     }
Line 53: }



how to solve it?
Posted
Comments
tumbledDown2earth 10-Apr-13 4:26am    
are you using a https channel or http?

Did you try this?

Either make:
smtp.Host = "https://smtp.gmail.com";

OR
smtp.EnableSsl = false;
 
Share this answer
 
Comments
aarohi verma 10-Apr-13 4:34am    
ya but its not working.
aarohi verma 10-Apr-13 8:15am    
Thanks. your suggesion is helpful to me.thank you.i do smtp.EnableSsl = false, and change my host name and port as per email control panel.
tumbledDown2earth 10-Apr-13 8:26am    
please vote the answer :)
HI AAROHI

Could you please check your SMTP.HOST. Are you having a Mail Server separately.


Rgds
Jagadesh
 
Share this answer
 
Comments
aarohi verma 10-Apr-13 4:36am    
you mean from my website control panel?
aarohi verma 10-Apr-13 8:13am    
Thanks, kumar i just check my control panel and change my host name and port and also do smtp.EnableSsl = false; and its done.thanks for direction.
Kumar from madras 10-Apr-13 8:42am    
HI TELL ME THE HOSTNAME THAT YOU INTRODUCED

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