Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
hi
 
i create a mail code like
 
MailMessage loginInfo = new MailMessage();
loginInfo.To.Add(txt_email.Text.ToString());
loginInfo.From = new MailAddress("my email id");
loginInfo.Subject = "Contact Detail";
loginInfo.Body = "Message: " + txt_message.Text; 
loginInfo.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.EnableSsl = true;
smtp.Credentials = new System.Net.NetworkCredential("my user name", "My password");
smtp.Send(loginInfo);
 

and it's work properly in localhost but i host this application and send mail when error are come like this
 
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 32:         smtp.EnableSsl = true;
Line 33:         smtp.Credentials = new System.Net.NetworkCredential("my id", "my pwd");
Line 34:         smtp.Send(loginInfo);
Line 35:     }
Line 36: }
Posted 6-Feb-13 18:33pm
Edited 15-Feb-13 2:53am
v4
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to add the following code and execute once for your application context.
 
System.Net.ServicePointManager.ServerCertificateValidationCallback = (s, certificate, chain, sslPolicyErrors) => true;
 
Actaully when use ssl then it use certificate and your web server try to validate that. In the above code you validated all certificates with true value. Please add this code to your Applicatin start event or some other place and redeploy the code and test it.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Check the below link. It shows the example of gmail.
 
sendind mail using smtp in asp.net[^]
 
You can also try the below its Gmail APIs
https://developers.google.com/google-apps/gmail/[^]
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 6,045
1 DamithSL 4,611
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 15 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100