通过smtplib库使用ssl安全连接发送邮件
需求 - 发送ssl安全邮件
使用126邮箱服务器通过ssl安全连接发送邮件。邮件内容为html格式,多个收件人。后续功能待补充。
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import logging
import os
import smtplib
from email.header import Header
from email.mime.text import MIMEText
file_dir = os.path.dirname(__file__) # 被执行脚本目录
log_path = os.path.join(file_dir, 'test_mail.log') # 脚本同目录下运行日志
def create_logger(file, encoding='UTF-8'):
"""
创建logger对象,记录日志
:param file:
:param encoding:
:return:
"""
handler = logging.FileHandler(file, encoding=encoding)
logging_format = logging.Formatter(
'%(asctime)s - %(levelname)s -%(filename)s - %(funcName)s - %(lineno)s - %(message)s')
handler.setLevel(logging.INFO)
handler.setFormatter(logging_format)
logger = logging.getLogger()
logger.setLevel(logging.INFO)

本文介绍如何使用Python的smtplib库通过SSL安全连接发送HTML格式的邮件,并解决了554退信的问题。
最低0.47元/天 解锁文章
669

被折叠的 条评论
为什么被折叠?



