python 发邮件,带附件,中文

聂炜
2023-12-01

 

 

# !/usr/bin/python
# -*- coding: UTF-8 -*-
from email import encoders
from email.mime.base import MIMEBase
from email.mime.multipart import MIMEMultipart
from email.utils import parseaddr, formataddr

import cv2
import os
import smtplib
import urllib
from email.mime.text import MIMEText
from email.header import Header

sender = 'aaa@163.com'
mail_user ='aaa@163.com'
receivers = []  # 接收邮件,可设置为你的QQ邮箱或者其他邮箱

# 第三方 SMTP 服务
mail_host = "smtp.com"  # 设置服务器

receivers.append("bbb@163.com")  # 用户名
mail_pass = "123456"  # 口令

def _format_addr(s):
    name, addr = parseaddr(s)
    return formataddr((Header(name, 'utf-8').encode(), addr))

def sendMsa(subject,content):
    try:
        msg = MIMEMultipart()
        message = MIMEText(content, 'plain', 'utf-8')
        msg.attach(message)
        # msg['From'] = He
 类似资料: