A very simple class to send e-mails using the Python SMTP standard lib.
from simplesmtp import SimpleSMTP
mail = SimpleSMTP(
host='mail.host',
username='[email protected]',
passw='password',
from_email='You <[email protected]>'
)
mail.send(to_email='[email protected]', subject='Hello', email_message='World')
# Changing default from_email
mail.send(
from_email='Another From <[email protected]>',
to_email='[email protected]',
subject='Hello',
email_message='World'
)
# Sending to more than one recipient
mail.send(
to_email='[email protected], [email protected]',
subject='Hello',
email_message='World'
)
# Attachments
mail.send(
to_email='[email protected], [email protected]',
subject='Hello',
email_message='World',
attachments=[
{
'file': '/path/to/real/file',
'filename': 'the name that you want'
}
]
)
Using SSL
from simplesmtp import SimpleSMTP
mail = SimpleSMTP(
host='mail.host',
username='[email protected]',
passw='password',
from_email='You <[email protected]>',
port=465,
use_ssl=True
)
mail.send(to_email='[email protected]', subject='Hello', email_message='World')
HTML messages
from simplesmtp import SimpleSMTP
mail = SimpleSMTP(
host='mail.host',
username='[email protected]',
passw='password',
from_email='You <[email protected]>'
)
mail.send(
to_email='[email protected]',
subject='Hello',
email_message='<html> HTML source with optional embedded images ... </html>',
msg_type='html'
)