I create new ASP.NET web application that use SMTP to send message. The problem is the smtp was not authenticated from who send the message.
How can I make SMTP authenticated in my program? does C# have a class that have attribute for enter username and password?
Ensure you set
SmtpClient.Credentials
after callingSmtpClient.UseDefaultCredentials = false
.The order is important as setting
SmtpClient.UseDefaultCredentials = false
will resetSmtpClient.Credentials
to null.Set the Credentials property before sending the message.
How do you send the message?
The classes in the
System.Net.Mail
namespace (which is probably what you should use) has full support for authentication, either specified in Web.config, or using theSmtpClient.Credentials
property.To send a message through TLS/SSL, you need to set Ssl of the SmtpClient class to true.
In my case even after following all of the above. I had to upgrade my project from .net 3.5 to .net 4 to authorize against our internal exchange 2010 mail server.
You may use the above code.