1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
|
import smtplib import sys from email.mime.text import MIMEText from email.header import Header
smtp_server = 'smtphz.qiye.163.com' mail_user = 'jwgod@163.com' password = 'xxxxxxxxx'
def mail(to, subject, txt): msg = MIMEText(txt, 'html', _charset='utf-8') msg['From'] = mail_user msg['To'] = to msg['Subject'] = Header(subject, 'utf-8').encode() try: s = smtplib.SMTP_SSL(smtp_server, port=465) s.login(mail_user, password) s.sendmail(mail_user, to, msg.as_string()) s.quit() except smtplib.SMTPException as e: print("Error: %s" % e)
def main(): if len(sys.argv) != 4: print('$1 to_user $2 Subject $3 Content') print(len(sys.argv)) sys.exit(1) else: mail(sys.argv[1], sys.argv[2], sys.argv[3])
if __name__ == '__main__': main()
|