python3.5.2,
代码:
from email.mime.text import MIMETextimport smtplib
msg = MIMEText('hello world','plain','utf-8')
#1、邮件内容。2、plain表示纯文本。3、utf-8编码
from_addr = "
12345@qq.com"#Email地址
password = "12345"#密码
to_addr = "
12345@qq.com"#收件人地址
port = 25
server = smtplib.SMTP(smtp_server, port)
#1、SMTP服务器。2、端口
server.set_debuglevel(1)#打印出与SMTP服务器交互信息,True打印,False不显示。(真假)
server.login(from_addr,password)
#1、Email地址。2、密码。登录STMP服务器
server.sendmail(from_addr, [to_addr], msg.as_string())#sendmail 发送邮箱,可以一次发送多人
#1、发送人,2、收件人,3、内容,as_string()把MIMEText对象变成str
server.quit()
然后等了很久 提示:
Traceback (most recent call last): File "regiemail.py", line 30, in <module>
server = smtplib.SMTP(smtp_server, port) File "/usr/local/python3/lib/python3.5/smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port) File "/usr/local/python3/lib/python3.5/smtplib.py", line 335, in connect
self.sock = self._get_socket(host, port, self.timeout) File "/usr/local/python3/lib/python3.5/smtplib.py", line 306, in _get_socket
self.source_address) File "/usr/local/python3/lib/python3.5/socket.py", line 711, in create_connection
raise err File "/usr/local/python3/lib/python3.5/socket.py", line 702, in create_connection
sock.connect(sa)TimeoutError: [Errno 110] Connection timed out
在win10上,直接执行代码成功,把代码传到阿里云的centos7上,就提示超时了.
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。