Disclaimer: I hesitated on the title, due to the broad nature of this question (see below ;-), other options included:
Thanks to these answers, to my additional questions: 1, 2, 3, as well as these two questions (and answers) of other people: one, two — I think I am now ready to answer the questions I have posted, on my own.
I will address the questions one by one:
Yes, as a general picture, sending of an email can be portrayed like this:
MX lookup returns address(es) of server(s) which receive email destined to the specified domain.
smtp-relay.gmail.com
, smtp.gmail.com
, aspmx.l.google.com
are not returned by host -t mx gmail.com
command?". This point is, pretty much, covered in another answer to this question. The main points to grasp here are:
Authentication is not needed, for servers receiving emails (i.e. the ones returned by MX lookup).
25
(which is default port for mail receiving servers), to prevent such "direct" mail sendingFrom
field, that is where you might be hit by DKIM)Code snippet is OK. The error is produced, in all probability, due to the blocking on the ISP's side.
With all that being said, code snippet:
import smtplib
from email.message import EmailMessage
message = EmailMessage()
message.set_content('Message content here')
message['Subject'] = 'Your subject here'
message['From'] = 'me@example.com'
message['To'] = 'user@example.com'
smtp_server = smtplib.SMTP('smtp.server.address:25')
smtp_server.send_message(message)
smtp_server.quit()
will actually send an email (see this question, for real-world, working example) given that smtp.server.address:25
is legitimate server and there are no blockings on ISP's and/or smtp.server.address
side.