Click here to Skip to main content
15,889,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HI guys
I am using
C#
System.Net.Mail;
to send mails in windows application .
all my credentials are right but i am getting "Authentication failed" Error message..

I have tried a lot but it didn't worked .. Can anyone Help me pls

this is the error message i am getting in depth...
<br />
{System.Net.Mail.SmtpException: Authentication failed.<br />
   at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)<br />
   at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)<br />
   at System.Net.Mail.SmtpClient.GetConnection()<br />
   at System.Net.Mail.SmtpClient.Send(MailMessage message)


here is the code:
C#
SmtpClient client = new SmtpClient();
                MailMessage msg = new MailMessage();
               
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                client.EnableSsl = false;
                client.Host =  "mail.xx.com";
                client.Port =  25;

                System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("username@xx.com", "pwd");
                client.UseDefaultCredentials = false;
                client.Credentials = credentials;
                msg.From = new MailAddress("ams@xx.com",System.Text.Encoding.UTF8);
                msg.To.Add(xx@gmail.com);
                msg.Subject = Subject;
                msg.SubjectEncoding = System.Text.Encoding.UTF8;
                msg.Priority = MailPriority.High;
                msg.Body = Body;
                msg.BodyEncoding = System.Text.Encoding.UTF8;
                msg.IsBodyHtml = true;

                msg.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                client.Send(msg);

Thanks In advance

[Edit]Code block added[/Edit]
Posted
Updated 27-Oct-12 5:20am
v3
Comments
kk2014 27-Oct-12 6:21am    
hi,
Please check username and password you are using for the same...
Hari Chandra Prasad Ravuri 27-Oct-12 6:27am    
hello kkakadiya

All credentials are correct sir .but still i am getting that error
xErvender 27-Oct-12 10:15am    
can you post the code?
Hari Chandra Prasad Ravuri 27-Oct-12 11:18am    
ok i have posted the code pls check it

Without your code to check how you are doing it, we can't rally help much.
However, this works: Sending an Email in C# with or without attachments: generic routine.[^] so it might be worth checking how you do it against that.
 
Share this answer
 
Hi

C#
MailMessage message = new MailMessage();

message.From = new MailAddress("userid@yahoo.com");
message.To.Add(new MailAddress("ngqandu.anele@gmail.com"));
message.Subject = subject.Text;
message.Body = body.Text;

SmtpClient client = new SmtpClient();
client.Credentials = new System.Net.NetworkCredential ("userid@yahoo.com", "password");

                client.Port = 587;
                client.Host = "smtp.mail.yahoo.com";
                client.EnableSsl = false;
                try
                {
                    client.Send(message);
                }
                catch (Exception ex)
                {
MessageBox.Show
            (ex.Message,"Information",MessageBoxButton.OK,MessageBoxImage.Information);
                }
 
Share this answer
 
Comments
Member 12295098 15-Mar-16 0:37am    
I am using Microsoft visual basic 2010, so whenever i use using System.Net.Mail; i am getting an error, even though i had added references. Need help
hinana 11-May-17 10:43am    
hello experts please i need help
i have an application and anytime i try it it says
System.Net.Mail.SmtpException: Authentication failed 5.5.1

i have read the solutions you give to the other guys. but am new in the coding so i cant fix that ...please where on my pc can i locate this codes to edit
thanks

please help
Anele Ngqandu 11-May-17 13:00pm    
hi, have a look at the accepted solution.http://stackoverflow.com/questions/13773810/system-net-mail-smtpexception-the-smtp-server-requires-a-secure-connection-or-t
also you can run the code from a console project.

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