开发者

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

I have a windows 2开发者_开发知识库003 / 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!


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...


Out of the box, IIS 6 will send using the built in SMTP server, Classic ASP usually default to using the pickup directory x:\inetpub\mailroot\pickup\. ASP creates an email file in here and when the SMTP service detects it, the mail is moved for processing. If you stop the 'Simple Mail Transfer Protocol' service, you should see files backing up in here, starting it again will make them all go out.

The SMTP Virtual server will appear in IIS Management, and from there you can set it to use your google account as a forwarder, or better still, you should adjust your mail function to use SMTP to Google instead of local. Presuming that you are using CDOSYS, use the following code to specify a mail server and logon details:

Dim ObjSendMail
Set ObjSendMail = CreateObject("CDO.Message") 

'This section provides the configuration information for the remote SMTP server.

ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'Send the message using the network (SMTP over the network).
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="mail.yoursite.com"
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False 'Use SSL for the connection (True or False)
ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

' If your server requires outgoing authentication uncomment the lines bleow and use a valid email address and password.
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 'basic (clear-text) authentication
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="somemail@yourserver.com"
'ObjSendMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="yourpassword"

ObjSendMail.Configuration.Fields.Update

'End remote SMTP server configuration section==

ObjSendMail.To = "someone@someone.net"
ObjSendMail.Subject = "this is the subject"
ObjSendMail.From = "someone@someone.net"

' we are sending a text email.. simply switch the comments around to send an html email instead
'ObjSendMail.HTMLBody = "this is the body"
ObjSendMail.TextBody = "this is the body"

ObjSendMail.Send

Set ObjSendMail = Nothing 

Source

You should monitor your mailroot folder from time to time, for the 'queue' and 'badmail' folders, even if the only action is to clear them out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜