最近公司的项目需要将测试报告以邮件形式发送出去,邮件为html格式。不过在公司内网无法通过一般的代理服务器发送邮件的,只能通过socks网关来访问外网的email服务器(我使用的同事已经搭好的socks5代理服务器)。
网上查找的主要方式都是使用PySocks来设置代理的:
import socks
import socket
socks.set_default_proxy(socks.HTTP, '地址', 端口, True, 用户名, 密码)
socket.socket = socks.socksocket
使用类似的方法设置了好几次还是不行,最后查到了一个chilkat库,官网上有比较详细的介绍:
https://www.example-code.com/python/smtp_socks_proxy.asp
发邮件模块
import sys
import chilkat
import time
def send_mail():
mailman = chilkat.CkMailMan()
mht = chilkat.CkMht()