Click here to Skip to main content
15,908,455 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello

I want to send user an email in my asp.net project, but I am receiving this error on run time:

The SMTP server requires a secure connection or the client was not authenticated.
The server response was: 5.7.1 Authentication required

What I have tried:

email class:
C#
public void SendEmailMethod(string ToEmail, string EmailSubject, string EmailBody)
        {
            EncryptData _EncryptData = new EncryptData();
            SmartLeavesDataContext db = new SmartLeavesDataContext();
            var _SiteSettings = db.SiteSettings.SingleOrDefault();
            string _Password = _EncryptData.Decrypt(_SiteSettings.EmailPassword);
            string _Email = _SiteSettings.EMail;

            string smtpAddress = "smtp.mail.yahoo.com";
            int smtpPort = 587;

            string EmailFrom = _Email;
            string Password = _Password;


            MailMessage Mail = new MailMessage();
            Mail.From = new MailAddress(EmailFrom);
            Mail.To.Add(ToEmail);
            Mail.Subject = EmailSubject;
            Mail.Body = EmailBody;
            Mail.IsBodyHtml = true;

            SmtpClient smtpObject = new SmtpClient(smtpAddress, smtpPort);
            smtpObject.Credentials = new NetworkCredential(EmailFrom, Password);
            smtpObject.EnableSsl = true;
            smtpObject.Send(Mail);
        }
Posted
Updated 17-Dec-16 6:21am
Comments
[no name] 17-Dec-16 11:39am    
Yahoo support says that the port to the mail is 465 not 587.
Ali Majed HA 17-Dec-16 11:52am    
hello
thanks for your comment,your solution has solved my problem, but this time I have the error : Failure sending mail. what does it refer to ? do I have error in my code ?
Dave Kreskowiak 17-Dec-16 11:53am    
No idea. That message is as generic as it gets. You have to look into the details of the exception for more information.
Ali Majed HA 17-Dec-16 11:54am    
thanks a lot for your help
Ali Majed HA 17-Dec-16 11:54am    
or maybe the password/email is wrong ?

1 solution

Continuing from the comments, 587 is correct port for Yahoo Mail and default TCP port for SMTP 25 also works, that is standard based and not Yahoo specific.

The problem is with your username/password combination, you need to check them out to make sure they are correct. Sending emails over .NET framework, and general problems – using C# code[^], consider using the code from that post and enter the details (only SMTP server host, username/password combination) to see if that works.

POP access settings and instructions for Yahoo Mail | Yahoo Help - SLN4724[^]
 
Share this answer
 

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