Search code examples
iisasp-classicsmtpgmail

Confused about SMTP / IIS and what actually happens with emails sent via ASP


I have a windows 2003 / IIS 6.5 machine running a classic ASP site.

The site itself sends emails ('forgot password', etc.) and I also run scripts on the machine to send email newsletters.

I don't have a real problem sending... but I am confused about how emailing actually works.

Is the SMTP server (IIS) ever communicating with my email provider (gmail for business) when I send from my website (I don't provide any login info)? Does my IIS SMTP server just blast emails out (maybe doing an MX lookup for the target?)? Is it the SPF record in the DNS records that allows this?

I just rebuilt our server (after disaster) and moved our email to gmail... so, I am setting this all up now... I can read all the 'how-to' articles - but unless I understand a few simple concepts, I won't really know what I am doing.

Thanks!


Solution

  • When sending a mail to someone, there's two SMTP servers involved.

    • Your own SMTP server (sender)
    • The recipients SMTP server (receiver)

    Basically, when you send a mail from your mailclient, your mailclient sends the mail to your own SMTP server, which then sends the mail to the recipients SMTP server. The reason for this (hop) is because servers may be down/slow/etc and your own server's responsibility is now to try and deliver the mail for (usually) within 48 hours.

    To find out what SMTP server the receipient has, the MX-records are looked up, by the sender SMTP, for the recipients domain:

    C:\> nslookup -type=mx hotmail.com
    Server:  dns.server.com
    Address:  183.255.245.11
    
    Non-authoritative answer:
    hotmail.com     MX preference = 5, mail exchanger = mx1.hotmail.com
    hotmail.com     MX preference = 5, mail exchanger = mx2.hotmail.com
    hotmail.com     MX preference = 5, mail exchanger = mx3.hotmail.com
    hotmail.com     MX preference = 5, mail exchanger = mx4.hotmail.com
    

    As you can see, multiple SMTP servers can be specified for a domain (for redundancy), and the sender SMTP will pick one based on priority (one that works). The mail is then sent to that server.

    And (if not using a webmail) the recipients mailclient may download that mail using e.g. POP3 or IMAP protocols.

    Now, when you send a mail from ASP.NET the sender SMTP server is usually the local IIS SMTP service, and not the usual SMTP server for your domain (the one that you yourself use to send mail; in your instance Gmail).

    SPF-records are records added to your DNS to specify what SMTP servers are allowed to send mail from your domain. Usually, IF you specify them, the receiver SMTP servers force that the the sender SMTP server is listed in the SPF record for the domain in the from-address. If you don't specify them however, mail is usually let though anyway, and other SPAM-filers kick in.

    Anyway, hope this helps to clarify things...