1. 程式人生 > >python模塊-發送郵件

python模塊-發送郵件

msg pla utf-8 gin mat author 內容 發送 sub

#!/usr/bin/env python
# -*- coding:utf-8 -*-
# author:Sun
# make_time:2018/8/2
import smtplib
from email.mime.text import MIMEText
from email.utils import formataddr


def sendmail_2018():
    msg = MIMEText('python', 'plain', 'utf-8')  # 郵件內容、類型默認:plain、默認字符集
    msg['From'] = formataddr(['python學院', '[email protected]'])  # 發送方
    msg['To'] = formataddr(['python', '[email protected]'])  # 接收方
    msg['Subject'] = 'python開發面試邀請'  # 主題
    server = smtplib.SMTP('smtp.163.com', 25)  # 郵件服務器
    server.login('郵箱', '密碼')  # 登陸
    server.sendmail('[email protected]', ['[email protected]', '[email protected]', ], msg.as_string())
    server.quit()

python模塊-發送郵件