|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我查了一些资料,实际操作时发现连接不上服务器,请问哪里有问题??
报错如下:
Traceback (most recent call last):
File "D:/pythontest/venv/ABC/163mailDemo.py", line 12, in <module>
smtp = smtplib.SMTP_SSL(mailserver,465)# 连接邮箱服务器,smtp的端口号是25
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 1030, in __init__
source_address)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 251, in __init__
(code, msg) = self.connect(host, port)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 336, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\smtplib.py", line 1036, in _get_socket
self.source_address)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\socket.py", line 704, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\socket.py", line 745, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11004] getaddrinfo failed
代码如下:
import smtplib
from email.mime.text import MIMEText
mailserver ="smtp.163.com" #邮箱服务器地址
username_send = 'xxxxxxxx@163.com' #邮箱用户名
password = 'xxxxxxx' #邮箱密码:需要使用授权码
username_recv = 'xxxxx@qq.com' #收件人,多个收件人用逗号隔开
mail = MIMEText('这是发用的邮件内容')
mail['Subject'] = '这是邮件主题'
mail['From'] = username_send #发件人
mail['To'] = username_recv #收件人;[]里的三个是固定写法,别问为什么,我只是代码的搬运工
smtp = smtplib.SMTP(mailserver,port=25)# 连接邮箱服务器,smtp的端口号是25
smtp.login(username_send,password) #登录邮箱
smtp.sendmail(username_send,username_recv,mail.as_string())# 参数分别是发送者,接收者,第三个是把上面的发送邮件的内容变成字符串
smtp.quit() # 发送完毕后退出smtp
print ('success')
|
|