简体   繁体   中英

Why doesn't a message appear when sending an email? - smtplib - Python

For some reason when trying to send an email no message appears, when I pass the string msg

Here's the code I'm using:

import smtplib

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login("my_email", "my_password")

msg = "my message"
server.sendmail("eggs@eggs.com", "eggs_2@eggs.com", msg)
server.quit()

Any alternative methods or solutions would be great.

Edit:

When I send the e-mail(to myself) no message appears just an empty e-mail appears in my inbox. Is there an alternative 'built-in' library that I can use?

The answer to my above question is:

The variable my_message just needs \\n before the text to separate it from the header.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM