- 报554的原因主题或内容中没有中文, 仅此而已
- setting.py
MAIL_USER = 'XXX@163.com'
MAIL_PASS = 'XXX' #不是邮箱登陆密码是开启smtp时的密码
MAIL_SENDER = 'XXX'
MAIL_HOST = 'smtp.163.com'
MAIL_PORT = 25
import smtplib
from email.mime.text import MIMEText
from email.header import Header
from setting import MAIL_SENDER, MAIL_HOST, MAIL_USER, MAIL_PASS, MAIL_PORT
def send_email(receivers, body_content, subject):
body_content = '内容:
{}'.format(body_content)
subject = '主题:{}'.format(subject)
message = MIMEText(body_content, 'plain', 'utf-8')
message['From'] = MAIL_SENDER
message['To'] = ','.join(receivers)
message['Subject'] = Header(subject, 'utf-8')
smtp_obj = smtplib.SMTP()
smtp_obj.connect(MAIL_HOST, MAIL_PORT)
smtp_obj.set_debuglevel(1)
smtp_obj.login(MAIL_USER, MAIL_PASS)
smtp_obj.sendmail(MAIL_SENDER, receivers, message.as_string())
smtp_obj.quit()send_email(receivers, body_content, subject):
#例
if __name__ == '__main__':
send_email(['XXX1@X.com', 'XXX2@X.com', 'XXX3@X.com'], 'x', 'y')