python2.4 发送邮件

import smtplib
#from email.mime.text import MIMEText
from email.MIMEText import MIMEText
def send_email(content):

    sender = "[email protected]"
    receiver = [[email protected]]
    host = '220.181.12.16'
    port = 465
    msg = MIMEText(content)
    msg['From'] = "[email protected]"
    msg['To'] = "[email protected]"
    msg['Subject'] = "backup check"

    try:
        smtp = smtplib.SMTP()
        smtp.connect('220.181.12.16:25')
#       smtp.ehlo()
#       smtp.starttls()
#       smtp.ehlo()

#        smtp = smtplib.SMTP_SSL(host, port)
        smtp.login(sender, 'xxxx')
        smtp.sendmail(sender, receiver, msg.as_string())
#        getlog().info("send email success")
    except Exception, e:
#        get_log().error(e)
        print 'email fail'
        print e
        pass
send_email('aaa')

你可能感兴趣的:(发送邮件,sendmail,python2.4)