|
10鱼币
本帖最后由 ietar 于 2019-7-22 17:37 编辑
(补充 问题已解决 腾讯云会默认限制25端口 安全组也没用 申请解封就行了)
(=(补充 windows环境下运行正常)
(补充阻塞具体信息图片)
centos7 问题定位在发送邮件这里了
sendmail的源码也贴出来了 测试的话注意把邮箱和密码换成自己的 还得开启smtp什么的
[code]from email import encoders
from email.header import Header
from email.mime.text import MIMEText
from email.utils import parseaddr, formataddr
import smtplib
def _format_addr(s):
name, addr = parseaddr(s)
return formataddr((Header(name, 'utf-8').encode(), addr))
def send(_from=r'ietarmailtest@163.com',\
password=r'麻烦填自己的邮箱和密码=.=',\
to=r'410473517@qq.com',\
message=r'nothing',\
title=r'来自smtp的问候......',\
yourname=r'ietar',\
addressee=r'hello?',\
debuglv=0):
'''directly send an email'''
if not isinstance(debuglv, int):
raise ValueError('debuglv should be 0 or 1')
smtp_server = r'smtp.' + _from.split(r'@')[1]
msg = MIMEText(message, 'plain', 'utf-8')
msg['From'] = _format_addr('{} <{}>'.format(yourname,_from))
msg['to'] = _format_addr('{} <{}>'.format(addressee,to))
msg['Subject'] = Header(title, 'utf-8').encode()
server = smtplib.SMTP(smtp_server, 25)
server.set_debuglevel(debuglv)
server.login(_from, password)
server.sendmail(_from, [to], msg.as_string())
server.quit()
def sendresetpassword(**kw):
return send(title='重置密码', **kw)
if __name__ == '__main__':
# send()
pass
[\code] |
|