简易发送邮件(仅限普通文本,发送邮箱需开启smtp),发送邮件smtp,若发送到139邮箱可通知


若发送到139邮箱可通知手机,自动给手机发送短信

import smtplib#easy send email, only can send plain textfrom email.mime.text import MIMETextfrom smtplib import SMTPHeloError, SMTPAuthenticationError, SMTPHeloError, SMTPSenderRefused#easy send email, only can send plain textdef sendmail(target, subject, content) :    msg  = MIMEText(content)    from_addr = "orighost@qq.com"    to_addr   = target    msg['Subject'] = subject    msg['From'] = from_addr    msg['To'] = to_addr    try:        s = smtplib.SMTP('smtp.qq.com')        s.login('orighost', '××××××')         s.sendmail(from_addr, to_addr, msg.as_string())    except SMTPHeloError:        print 'Error: Can not connect server.'        return 1    except SMTPAuthenticationError:        print 'Error: Username or password is not correct.'        return 1    except SMTPHeloError:        print 'Error: Can not deliver to target host.'        return 1    except SMTPSenderRefused:        print 'Error: The target server don\\'t accept you from_addr'        return 1    except:        print "Send failed"        return 1        pass    finally:        s.quit()    print "Send success."    return 0if __name__ == "__main__":    sendmail("orighost@qq.com", "hello", "welcome to use the email.")#该片段来自于http://byrx.net

评论关闭