直接上代码
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 |
# -*- coding:utf-8 -*- from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText import smtplib # 输入Email地址和口令: from_addr = input('From: ') password = input('Password: ') # 输入收件人地址: to_addr = input('To: ') # 输入SMTP服务器地址: smtp_server = input('SMTP server: ') msg = MIMEMultipart() msg['Subject'] = 'duangduang!' msg['From'] = from_addr msg['To'] = to_addr content = ''' 你好, 这是一封自动发送的邮件。 http://www.xyu.ink ''' txt = MIMEText(content, 'plain', 'utf-8') msg.attach(txt) server = smtplib.SMTP(smtp_server, 25) # SMTP协议默认端口是25,SSL默认端口465/994,如果报错请尝试465端口 server.set_debuglevel(1) server.login(from_addr, password) server.sendmail(from_addr, [to_addr], msg.as_string()) server.quit() |