June 17th, 2010, 05:49 PM
Some conceptual questions about how mail works
I have some conceptual questions about how mail works. I'm a web programmer w/ limited sysadmin experience. I've always taken for granted that the server I'm programming on is able to send out email. Typically, I use PHP's mail() function and it just works. Now I'm working on a server (Windows Server) that is not running an SMTP server, so I need to figure out how to send out mail.
Let's say my server is foo.bar.org and I work for bar.org, which has many servers. I want the webserver on foo to be able to send out email. I think that one way to do this is to get an email address from bar.org (which has an SMTP server running), and set up the webserver on foo to connect to that SMTP server to send out email. Will that work?
I think that another way to make this work is to run an SMTP server on foo, and have the webserver connect to it (i.e., on localhost). But then how does the SMTP server know which machine to connect to, to send and receive emails? Does it connect directly to the SMTP server named in the email's "To:" field? In other words, if the email is address to "email@example.com", will my SMTP server connect directly to port 25 on microsoft.com?
June 17th, 2010, 06:07 PM
Sort of. It actually looks up the DNS records for the domains in the to field, identifies the MX records and then contacts one of the SMTP servers running on the addresses specified in the MX records.
June 18th, 2010, 12:19 AM
If your windows server has IIS, most versions of IIS have an optional built-in SMTP server. If you have another mail server on the same LAN usually that works fine.
Using external smtp servers from server-side code can be problematic. The SMTP port is often blocked by admins or ISP's. The remote SMTP server may think you're a spammer and reject connections from your server.
But you can use external smtp servers, I use my ISP smtp server with local web code.
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi