Click here to Skip to main content
12,452,083 members (25,298 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# SMTP Mail
here is my code:
System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
                    message.To.Add("gabitza.sas@gmail.com");
                    message.Subject = "Nici un Clinet valabil pentru reparare";
                    message.From = new System.Net.Mail.MailAddress("gabitza.sas@gmail.com");
                    message.Body = "Nu mai sunt clienti la care mecanicii sa lucreze";
                    string sendEmailsFrom = "gabitza.sas@gmail.com";
                    string sendEmailsFromPassword = "my_invisible_password";
                    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
                    smtp.EnableSsl = true;
                    smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
                    smtp.Credentials = new NetworkCredential(sendEmailsFrom, sendEmailsFromPassword);
                    smtp.Timeout = 20000;
                    smtp.Send(message);

And my error:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

What is the problem? i can't see it and can't find a solution on google.

Thanks,
Sas Gabriel
Posted 12-Nov-12 10:48am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

You need to set
UseDefaultCredentials = false;
first and after that set the credentials you want to use

Credentials = new NetworkCredential("gabitza.sas@gmail.com", "my_invisible_password");

Also make sure you can login from with your username and password from the mail.google.com page.

Good luck,
OI
  Permalink  
Comments
Gabriel Sas 12-Nov-12 17:04pm
   
also the password wasn't the good one, thanks
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Also please be aware that google will block you from logging in when you do to much connection attempts.

I always use a local email server for development: http://www.hmailserver.com/[^]
It's free. You can simply configure it and run it on your computer, connecting to localhost:2525.
Please be sure to also turn down the ban-option ("auto-ban") of this one.
  Permalink  

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 13 Nov 2012
Copyright © CodeProject, 1999-2016
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