Send email notification

rtilley rtilley at vt.edu
Tue Mar 7 23:15:31 CET 2006


Ernesto wrote:
> Is there a special module for mail ?
> 
> I'd like to send an email [to 'n' unique email addresses] from a python
> script.  

    from email.MIMEText import MIMEText
    import email.Utils
    import smtplib

    # 'users' is a list of email addys.
     for u in users:
        try:
            print "Sending email to ... ", u
            f = "FROM_NAME<FROM_EMAIL_ADDY at YOUR_DOMAIN.com>"
            t = u

            msg = MIMEText("""MESSAGE BODY OF EMAIL""")

            msg["Subject"] = "MESSAGE SUBJECT"
            msg["Message-id"] = email.Utils.make_msgid()
            msg["From"] = f
            msg["To"] = t

            h = "YOUR.SMTP.SERVER"
            s = smtplib.SMTP(h)
            s.sendmail(f, t, msg.as_string())
            s.quit()
        except Exception, e:
             print e



More information about the Python-list mailing list