我想向excel表格文件中的电子邮件列表发送电子邮件
我正在使用VisualStudio代码和Linux操作系统
请在下面检查我的代码:
import pandas as pd
import smtplib
SenderAddress = "my@emailaddress"
password = "mypassword"
e = pd.read_excel("email.xlsx")
emails = e['Emails'].values
server = smtplib.SMTP("smtp.gmail.com ", 587)
server.starttls()
server.login(SenderAddress, password)
msg = "Hello this is a email form python"
subject = "Hello world"
body = "Subject: {}\n\n{}".format(subject, msg)
for email in emails:
server.sendmail(SenderAddress, email, body)
server.quit()
运行代码时,出现以下错误:
line 9, in <module>
server = smtplib.SMTP("smtp.gmail.com ", 587)
File "/usr/lib/python3.8/smtplib.py", line 253, in __init__
(code, msg) = self.connect(host, port)
File "/usr/lib/python3.8/smtplib.py", line 339, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "/usr/lib/python3.8/smtplib.py", line 308, in _get_socket
return socket.create_connection((host, port), timeout,
File "/usr/lib/python3.8/socket.py", line 787, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "/usr/lib/python3.8/socket.py", line 918, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno -2] Name or service not known
[Done] exited with code=1 in 0.683 seconds
我们需要
ehlo
,如下所示:主机名末尾有一个空格
移除空间
相关问题 更多 >
编程相关推荐