I\'m using the following method to send mail from Python using SMTP. Is it the right method to use or are there gotchas I\'m missing ?
from smtplib import SM
See all those lenghty answers? Please allow me to self promote by doing it all in a couple of lines.
Import and Connect:
import yagmail
yag = yagmail.SMTP('john@doe.net', host = 'YOUR.MAIL.SERVER', port = 26)
Then it is just a one-liner:
yag.send('foo@bar.com', 'hello', 'Hello\nThis is a mail from your server\n\nBye\n')
It will actually close when it goes out of scope (or can be closed manually). Furthermore, it will allow you to register your username in your keyring such that you do not have to write out your password in your script (it really bothered me prior to writing yagmail
!)
For the package/installation, tips and tricks please look at git or pip, available for both Python 2 and 3.