Very simple email sending method in python

I needed to send an email, so I came up with this:

 
def send_plain_mail(subject, body, from_mail, to):
    import smtplib
    from email.MIMEText import MIMEText
    from email.Encoders import encode_quopri
 
    msg = MIMEText(body, 'plain', 'iso-8859-1')
 
    msg['Subject'] = subject
    msg['From'] = from_mail
    msg['To'] = to
 
    s = smtplib.SMTP()
    s.connect()
    s.sendmail(from_mail, [to], msg.as_string())
    s.close()

Not rocket science, but it gets the job done.

This entry was posted in Uncategorized and tagged , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">