Sending email using python smtplib does not work, confused in the "from" field

I am trying to send an email in python. Here is my code.

import smtplib

if __name__ == '__main__':
SERVER = "localhost"

FROM = "sender@example.com"
TO = ["wmh1993@gmail.com"] # must be a list

SUBJECT = "Hello!"

TEXT = "This message was sent with Python smtplib."

# Prepare actual message

message = """\
From: %s
To: %s
Subject: %s

%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)

# Send the mail

server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO[0], message)
server.quit()
print "Message sent!"

This runs without error, but wmh1993@gmail.comno email is sent.

Questions

One thing I don’t understand about this code: what limitations do I have when setting up a field FROM?

Do I have to say somehow that it was from my computer?

What happens so as not to disturb someone else?

Or am I free to do this?

+5
source share
2 answers

This works without errors, but no email is sent to wmh1993@gmail.com .

, MTA ( ) "localhost", gmail. , , bounce "sender@example.com", . , gmails ( -, )

, : FROM?

- , ?

. , . // IP-? gmail ( ) IP-. HELO , DNS .. . , , smarthost, .

, - ?

, . , SPF/DKIM, , SMTP .

?

.

+6

, , , . , HOST PORT . :

HOST = "smtp.gmail.com"
PORT = "587"
SERVER = smtplib.SMTP()
SERVER.connect(HOST, PORT)

. :

USER = "myuser@gmail.com"
PASSWD = "123456"

TLS. :

SERVER.starttls()

. :

SERVER.login(USER,PASSWD)

sendmail. . , , , . , .

0

All Articles