Does smtplib lookup MX records?

Steve Holden sholden at holdenweb.com
Fri Nov 16 19:34:48 CET 2001


"Dale Strickland-Clark" <dale at riverhall.NOTHANKS.co.uk> 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.)
>
The intention with smtplib.sendmail() is that the host you send through
should itself be a mail server, which will be prepared to look up the
appropriate MX records. If you just take the domain from an email address
and use that as the smtplib host you will usually see errors.

In case you really do need to look up the appropriate MX hosts I am sending
some code by email, rather than clutter up c.l.py with something so
esoteric.

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list