I've recently switched all of my email over to Google Apps. One side
effect of that is that all of my applications had to be updated to send
email through the Google servers rather than the email servers I was
using.
I was actually able to do it with only one minor code
change and a change to the web.config. First, the web.config mail
settings section:
<system.net><mailSettings>
<smtp from="user@domain.com">
<network host="smtp.gmail.com" port="587" userName="user@domain.com" password="pwd" />
</smtp>
</mailSettings>
</system.net>
Obviously, substitute your own email address and password, but once
you've done that, this configuration should work. One shortcoming I see
with the configuration is that it doesn't allow us to specify the use
of SSL, which Gmail requires. So that's the one code change:
1: System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
2: client.EnableSsl = bool.Parse(ConfigurationManager.AppSettings["MailSSL"]);
To shield myself from code changes in the future, I added an
app setting to determine if I want SSL. That way, in the future, if I
move back to a non-Gmail account to send mail from, I just change the
mailSettings section, change MailSSL to be false, and I'm good to go.
Just a note that I did try port 465 (another port supported by
Gmail) to send mail initially, and got a timeout every time, so I
switched to 587, and mail started going through just fine.