We have gmail for our corporate email provider.
I want to be able to send mail through smtp.gmail.com
from ASP.NET. I have managed to do this just fine - and it has the benefit of all sent items appearing in the correct sent items folder within gmail. However it can take up to 2-3 seconds to make a connection to smtp.gmail.com
. Occasionally it will even fail completely. Since this is ASP.NET app I need to be able to reliably send email. I don't want to have to go and create some email daemon of my own - i just want to rely on SMTP.
I've tried with the Virtual SMTP Server on IIS6 but haven't been able to get it to work. An active current session
is shown for up to a minute and then it disappears.
Do I need to use something like sendmail to do this - or some other free SMTP relay that gives me better control? I even found a sourceforge project called 'Gmail SMTP Relay' - and the hosted server we're using has installed - which has its own SMTP server.
I'd prefer something graphical - and most of all I'd prefer the Microsoft SMTP server becasue I already have it installed.
I fought with this for a few weeks. Here are the settings that I'm using on 3 ASP.NET websites that use SMTP gateway to send their emails:
Address: smtp.gmail.com Port: 587
1) The port is very important. You may have to enter it like smtp.gmail.com:587 in your SMTP server. I haven't touched Microsoft SMTP in years, so I can't remember what the setup screen looks like.
2) Make sure to enable SSL for SMTP, as gmail requires it.
3) SMTP Authentication should be set to Basic.
4) Make sure that you are using an actual email and not an email alias to authenticate. This one gave me lot of trouble.
This is how I got it working.
Found this explanation here of exactly what I needed (when using IIS) :
http://fmuntean.wordpress.com/2008/10/26/how-to-configure-iis-smtp-server-to-forward-emails-using-a-gmail-account/
I am sending mail using this C# code
Note: the communication between my C# app and my local SMTP server is not encrypted (hence the EnableSsl=false) - but the communication between my SMTP server and GMAIL is encrypted (see the linked doc for more).
Important tip: If you are using the Microsoft SMTP client to relay mail make sure you don't have any domains in the 'Default SMTP Virtual Server > Domains' list. if so any email addressed to those domains will end up in
C:\Inetpub\mailroot\Drop
- which is probably not what you want in this instance. I just renamedmydomain.com
to (literally)example.com
after having problems with outgoing mail not actually going out.