I\'m trying to fix an email issue with an inherited website and don\'t have access to the code (i.e. just the compiled files). This site needs to be hosted on a new web serv
Set IIS to forward your mail to the remote server. The specifics vary greatly depending on the version of IIS. For IIS 7.5:
I don't have enough rep to answer ClintEastwood, and the accepted answer is correct for the Web.config file. Adding this in for code difference.
When your mailSettings are set on Web.config, you don't need to do anything other than new up your SmtpClient and .Send. It finds the connection itself without needing to be referenced. You would change your C# from this:
SmtpClient smtpClient = new SmtpClient("smtp.sender.you", Convert.ToInt32(587));
System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("username", "password");
smtpClient.Credentials = credentials;
smtpClient.Send(msgMail);
To this:
SmtpClient smtpClient = new SmtpClient();
smtpClient.Send(msgMail);
Web.Config file:
<configuration>
<system.net>
<mailSettings>
<smtp from="yourmail@gmail.com">
<network host="smtp.gmail.com"
port="587"
userName="yourmail@gmail.com"
password="yourpassword"
enableSsl="true"/>
</smtp>
</mailSettings>
</system.net>
</configuration>