Yes, like the answer, this is an authentication question :)
I would also like to help you send emails by reporting the yagmail package (I'm a supporter, sorry for the ad, but I feel this can really help!). Please note that I also maintain a list of common errors, such as authentication failure.
All code for you:
import yagmail yag = yagmail.SMTP('user', 'pw') yag.send(contents = msg)
Please note that I provide default values ββfor all arguments, for example, if you want to send yourself, you can omit " to = myemail@gmail.com ", if you do not want a subject, you can also omit it.
In addition, the goal is also to make it very easy to attach html code or images (and other files).
When you put the content, you can do something like:
contents = ['Body text, and here is an embedded image:', 'http://somedomain/image.png', 'You can also find an audio file attached.', '/local/path/song.mp3']
Wow, how easy it is to send attachments! It takes 20 lines without yagmail;)
In addition, if you install it once, you no longer have to enter a password (and store it safely). In your case, you can do something like:
import yagmail yagmail.SMTP().send(contents = contents)
which is much more concise!
I invite you to take a look at github or install it directly using pip install yagmail .