Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi frds,

Getting error while sending a mail using asp.net .. i have tried many coding's to send mail but not working ..
i have tried like this
C++
msg.From = new MailAddress("test@gmail.com");
       msg.To.Add("test@gmail.com");
       msg.Subject = "test";
       msg.Body = "Test Content";
       //msg.Priority = MailPriority.High;


       using (SmtpClient client = new SmtpClient())
       {
           client.EnableSsl = true;
           client.UseDefaultCredentials = false;
           client.Credentials = new NetworkCredential("test@gmail.com", "test");
           client.Host = "smtp.gmail.com";
           client.Port = 587;
           client.DeliveryMethod = SmtpDeliveryMethod.Network;

           client.Send(msg);
       }

its getting an error that
C++
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.


Please give me the code to send the mail using gmail credentials ..please help me ..
thanks in advice..
mani..
Posted
Updated 17-Mar-15 0:56am
v2
Comments
F-ES Sitecore 17-Mar-15 7:12am    
Log into your gmail account via the web interface and ensure it's not asking you to do the "captcha", as it won't allow you to send via smtp if your account is in captcha mode (just one of many reasons why you shouldn't use gmail's smtp servers) and configure it to allow smtp access. Also try the code here

http://www.aspsnippets.com/Articles/Send-email-using-Gmail-SMTP-Mail-Server-in-ASPNet.aspx

The best solution is to use the SMTP provided by your host, not gmail.
u mani 17-Mar-15 7:23am    
thanks for ur reply
u mani 17-Mar-15 8:07am    
hi one doubt in local host mails are gng when i deployed getting an error that Security Exception .. please tell me

1 solution

Hi,

1) https://accounts.google.com/DisplayUnlockCaptcha //Click allow access to your Google account
2) You have to enable login from other timezone / ip for your google account.

to do this follow the link https://g.co/allowaccess and allow access by clicking the continue button.
3) go to security settings at the followig link https://www.google.com/settings/security/lesssecureapps and enable less secure apps . So that you will be able to login from all apps.

Ref : 5.5.1 Authentication Required
 
Share this answer
 
Comments
u mani 17-Mar-15 7:14am    
thank u very much its working for me
[no name] 17-Mar-15 7:15am    
Welcome :)
u mani 17-Mar-15 8:05am    
hi one doubt in local host mails are gng when i deployed getting an error that Security Exception .. please tell me
[no name] 17-Mar-15 8:23am    
put a break point and check which part u get the error?
Ref : Click here
u mani 17-Mar-15 8:44am    
smtp.Port = 587; here i am getting this error ... in local host there is no problm .. when i run in server getting error smtp.Port = 587; here Security Exception like this

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