Does smtplib lookup MX records?

Just van Rossum just at letterror.com
Fri Nov 16 14:05:43 EST 2001


Dale Strickland-Clark wrote:

> I've been trying to send emails with smtplib and had a large number of
> failures. Investigation seems to reveal the the smtplib module does a
> simple connect passing the hostname to socket.connect without trying
> to resolve the MX record.
> 
> In some cases this works where the mail server happens to have an
> A-type DNS record anyway but otherwise it fails with a connection
> error.
> 
> Is this really the case?
> 
> If it is, what do I need to do to lookup the MX record myself?
> 
> (This is rather urgent now as this program was hastily written to help
> a client out who's mail server has died.)

Are you sure you're using smtplib correctly? I *think* it's mostly meant
to talk to a local relay host (eg. smtp.my-isp.com). The smtp server
will take care of the rest. If you insist on delivering yourself, then
yeah, you'd have to look up the mx record for each recipient, but I
wouldn't consider that typical usage of smtplib. Am I missing something?

Just



More information about the Python-list mailing list