Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.44/5 (2 votes)
See more:
Hi,
I used this code to sending email from my desktop application
C#
string smtpAddress = "smtp.gmail.com";
            int portNumber = 587;
            bool enableSSL = true;

            string emailFrom = "xyz@gmail.com";
            string password = "myPassword";
            string emailTo = "xyz@yahoo.com";
            string subject = "Hello";
            string body = "Hello, I'm just writing this to say Hi!";

            using (MailMessage mail = new MailMessage())
            {
                mail.From = new MailAddress(emailFrom);
                mail.To.Add(emailTo);
                mail.Subject = subject;
                mail.Body = body;
                mail.IsBodyHtml = true;
                // Can set to false, if you are sending pure text.

                mail.Attachments.Add(new Attachment("C:\\n.txt"));

                using (SmtpClient smtp = new SmtpClient(smtpAddress, portNumber))
                {
                    smtp.Credentials = new NetworkCredential(emailFrom, password);
                    smtp.EnableSsl = enableSSL;
                    smtp.Send(mail);
                }
            }


and i have this error
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Authentication required

any help ?
Posted
Updated 28-Aug-17 4:54am
v3
Comments
Shweta N Mishra 28-Nov-14 8:36am    
do you have a smtp configured at your end ?
You can not access yahoo's SMTP, you do not have access to it.
Heba Kamel 28-Nov-14 8:46am    
No, how can I do this?
I can change yahoo's SMTP to GMail's SMTP (smtp.gmail.com), right?
Richard MacCutchan 28-Nov-14 8:57am    
You need to have an account with the SMTP service to use it for email, whether it is Yahoo or gmail.
Heba Kamel 28-Nov-14 18:41pm    
How can i get this account, and where i used this account in my code?
Richard MacCutchan 29-Nov-14 4:23am    
Go to gmail and create it.

I have tested this entire code in my own IDE and the result for this problem was the username/password match error.

Make sure that you're using the correct password for the valid username on the server.

Possible issue: You're asking a question about Gmail, but you're using the Yahoo smtp server. Are you sure you're using the correct settings for credentials for the Yahoo server, or did you mistakenly wrote that Yahoo smpt host address?
 
Share this answer
 
v2
Comments
Heba Kamel 28-Nov-14 8:56am    
i wrote this line
Smtp.Port = 25;
but still error

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first. c5sm16036467wik.3 - gsmtp
Afzaal Ahmad Zeeshan 28-Nov-14 10:04am    
Did you try writing it inside the using block?
Afzaal Ahmad Zeeshan 28-Nov-14 14:22pm    
Please see my updated answer.
Heba Kamel 28-Nov-14 17:57pm    
Sorry, it's mistake i mean Gmail smtp (smtp.gmail.com)
yes, i used it in using block
in this line
smtp.Credentials = new NetworkCredential("xyz@gmail.com", password);
i must write email or user name in first parameter?
Heba Kamel 28-Nov-14 18:45pm    
Make sure that you're using the correct password for the valid username on the server .

Did you mean my email password ?
first
string smtpAddress = "smtp.gmail.com";
second
check ur credentials , username and password of ur account
 
Share this answer
 
Comments
Heba Kamel 28-Nov-14 17:58pm    
Did you mean in this line i must write user name rather than email in first parameter ?
smtp.Credentials = new NetworkCredential("xyz@gmail.com", password);
[no name] 15-Aug-16 9:50am    
Hi afzal did you get the solution. I have the same problem, unable to figure out what to do

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