Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying to send an email from c# code using SMTP.

I am using third party SMTP. (Not using gmail SMTP).
Its login credentials are working perfectly.

but when i try to send send email it is giving me an error.

Getting error message

"Sending fail: The SMTP server requires a secure connection or the client was not authorized. The server response was SMTP authentication is required"


SenderEmailAddress and SenderEmailPasswor are passed to method as a parameter.

I have already tried suggestion found on codeproject but not working for me

What I have tried:

C#
var email = new MailMessage();
var GmailSmptp = new SmtpClient();

GmailSmptp.Host = "mail.xyz.com";
               
GmailSmptp.UseDefaultCredentials = false;

GmailSmptp.EnableSsl = false;
GmailSmptp.Port = 465;
GmailSmptp.Port = 26;

GmailSmptp.Credentials = new NetworkCredential(SenderEmailAddress,SenderEmailPassword);


email.To.Add(EmailTo);
email.From = new MailAddress(SenderEmailAddress);
email.Subject = EmailSubject;
email.Bcc.Add(SenderEmailAddress);
email.IsBodyHtml = true;

GmailSmptp.Send(email);
Posted
Updated 28-Jul-21 20:23pm
v2

1 solution

1) You set the port number twice, which makes no sense.
Which port do you want to use? 465 or 26?

Ask your email provider for the right settings
(Host, Port, Credentials)
We do not know these settings...

2) If they require SSL then you must set EnableSsl to true.
 
Share this answer
 
Comments
Devendra Sarang 29-Jul-21 2:51am    
2.Regarding 2nd point

I have made ssl connection to true "GmailSmptp.EnableSsl = true" and try to send email.

At that time, getting error message like "Server does not support secure connections"

which means that my smtp is not supporting SSL. Right ?
TheRealSteveJudge 29-Jul-21 3:00am    
This is what you must ask your provider.
Maybe they have two ports,
one SSL port and one non SSL port.
Devendra Sarang 29-Jul-21 3:16am    
port number 26 giving

"The SMTP server requires a secure connection or the client was not authenticated. The server response was: SMTP authentication is required."

and port number is 465 giving

"the operation has timeout"
Devendra Sarang 3-Aug-21 1:33am    
today i have try to send email using same code using gmail smtp and once again getting same smtp error

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