Click here to Skip to main content
14,391,564 members
Rate this:
Please Sign up or sign in to vote.
No answer found even after searching many sites

i am using VS2010(Frame work 4.0) and SQL 2012 , we are using exchange server....same mail configuration is working in java application but not working in c#

button click code is :

try
{
SmtpClient smtp = new SmtpClient();
smtp.Host = "mail.myorganization.com"
smtp.Port = "587";
smtp.Credentials = new System.Net.NetworkCredential("abc@myorganization.com", "password");
smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
smtp.EnableSsl = true;
MailMessage msg = new MailMessage();
msg.From = new MailAddress("abc@myorganization.com");
msg.To.Add(new MailAddress("receiver@something.com"));
msg.Subject = "Test";
msg.Body = "Test mail";
smtp.Timeout = 60000;
smtp.Send(msg);
result = true;
}
catch (Exception ex)
{

}
My exception error is

System.Net.Mail.SmtpException was caught
HResult=-2146233088
Message=Authentication failed.
Source=System
StackTrace:
at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
at System.Net.Mail.SmtpClient.GetConnection()
at System.Net.Mail.SmtpClient.Send(MailMessage message)
at MailConfiguration.TestMail() in
Posted
Comments
Krunal Rohit 12-Oct-15 7:07am
   
And the error is ?

[Haven't seen the exception. Apologies]

-KR
kiran kumar 12-Oct-15 8:08am
   
error is "Authentication failed"
kiran kumar 18-Nov-15 8:03am
   
host\port\credentials\ssl settings all are correct. I used same credentials in java application. It is working in Java App, but failed in failed in .Net App. Any help ??

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Set UseDefaultCredentials to false before you set the Credentials property

https://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.usedefaultcredentials(v=vs.110).aspx[^]
   
Comments
kiran kumar 12-Oct-15 7:15am
   
Thanks for your reply. smtp.UseDefaultCredentials = false; i used this but no use, mail sending failed.
F-ES Sitecore 12-Oct-15 7:24am
   
Check with your network admin to ensure the host\port\credentials\ssl settings are all correct. For example if you use SSL then the port might be 465, there is no point in guessing though, and we can't know how your smtp server is configured, you'll need to ask the people that know.
kiran kumar 12-Oct-15 7:49am
   
i tried with port number 465. mail sending failed.
kiran kumar 18-Nov-15 8:03am
   
host\port\credentials\ssl settings all are correct. I used same credentials in java application. It is working in Java App, but failed in failed in .Net App. Any help ??

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100