1. 首页
  2. IT资讯

TC企业邮Python3 SMPT SSL 发件脚本

#!/usr/bin/python3
 
import smtplib
 
from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.utils import parseaddr, formataddr
 
def _format_addr(s):
    name, addr = parseaddr(s)
    return formataddr((Header(name, 'utf-8').encode(), addr))
 
from_addr = "mymail@domain.com"
password = "clear-text_passwd"
to_addr = "tomail@domain.com"
smtp_server = "smtp.exmail.qq.com"
 
msg = MIMEMultipart('alternative')
msg['From'] = _format_addr('myname <%s>' % from_addr)
msg['To'] = _format_addr('toname <%s>' % to_addr)
msg['Subject'] = Header('一封来自银河系外的测试邮件,请倒立后开启', 'utf-8').encode()
 
msg.attach(MIMEText("Hi, It's a AutoSend EMail Script test.\n\nThe End", 'plain', 'utf-8'))
msg.attach(MIMEText("""
<html>
    <body>
        <h1>Hi, It's a AutoSend EMail Script test.</h1>
        <p align="center"><img src="http://www.baidu.com/img/bd_logo1.png"></p>
        <p>The End<p>
    </body>
</html>
""",'html', 'utf-8'))
 
server = smtplib.SMTP_SSL(smtp_server, 465) # 注意,非SSL使用smtp.SMTP()
server.set_debuglevel(1)
server.login(from_addr, password)
server.sendmail(from_addr, [to_addr], msg.as_string())
server.quit()

测试的时候,写了个循环给自己发送100封邮件,没做条件,结果就触发了发信频率限制,直接就拒绝请求550,问了客服,才知道分钟小时日都有发信频率限制。

本文来自投稿,不代表程序员编程网立场,如若转载,请注明出处:http://www.cxybcw.com/200420.html

联系我们

13687733322

在线咨询:点击这里给我发消息

邮件:1877088071@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

QR code