I have a small WinForms application that sends notification emails. It works fine with outlook clients but bombs if a gmail/yahoo/windowslive address is entered. I’ve seen many posts using system.web.mail and schemas but Visual Studio 2010 gives me an error when trying to use this (I’m assuming because of .Net 2.0). Is it possible to configure my smtp client code to relay to all of these email providers?
Im using system.net.mail with MailMessage. My configuration code is below…
SmtpClient mailSender = new SmtpClient("smtp.myclient.com");
mailSender.EnableSsl = true;
mailSender.Send(message);
It works fine for Outlook clients because the workstation is (likely) logged into the Active Directory Domain and the Exchange server “trusts” the connection because of it.
You need to add the user’s credentials on the mail service, and you’ll have to get them from the user:
Also, don’t forget to set the Port property for SSL. Some providers don’t use the standard ones.