Given an email address is it possible to determine what the smtp address is using python. I am building an email application using python smtplib.
Thanks
The Python smtplib
module does not perform mail routing, so it leaves that to a smart host.
You could use dnspython
to look up MX records for the destination domain (and A and AAAA records if there is no MX record). The resulting address you can then pass to smtplib
.
However, this is only a small fraction of the work that is needed to implement proper mail routing: If the target mail server is unreachable or times out, you are supposed to try the next server. Similarly if it responds with a 4xx
error code. If all servers are unavailable, you need to temporarily store the message locally, so you need to implement your own mail queue. Furthermore, your external IP address may be blacklisted for mail delivery.
Therefore, it is usually easier to install a local mail server such as Exim or Postfix and use that to inject mail, possibly routing it via a smart host with good email reputation to avoid blacklisting.