[英]Error Sending Email using Gmail with SMTP (Python 3)
I am trying to use SMTP in Python 3.4 to send emails but I am receiving the following error when I run my code:我正在尝试在 Python 3.4 中使用 SMTP 发送电子邮件,但在运行代码时收到以下错误:
Traceback (most recent call last):
File "C:/Users/Anna Hughes/Documents/Python Projects/2015.10.16/Mail Application.py", line 9, in <module>
server.login(user_email, user_password)
File "C:\Python34\lib\smtplib.py", line 613, in login
raise SMTPException("SMTP AUTH extension not supported by server.")
smtplib.SMTPException: SMTP AUTH extension not supported by server.
Here is my code:这是我的代码:
import smtplib
server = smtplib.SMTP("smtp.gmail.com:587")
user_email = "user@gmail.com"
user_password = "password"
recipient_email = "recipient@gmail.com"
msg = "Test."
server.login(user_email, user_password)
server.ehlo()
server.starttls()
server.sendmail(user_email, recipient_email, msg)
server.quit()
Thanks.谢谢。
EDIT:编辑:
I have changed the second line to server = smtplib.SMTP("smpt.gmail.com, 587")
as suggested.我已按照建议将第二行更改为
server = smtplib.SMTP("smpt.gmail.com, 587")
。 That seemed to fix the error, but I am now getting a new one:这似乎解决了错误,但我现在得到了一个新的:
Traceback (most recent call last):
File "C:/Users/Anna Hughes/Documents/Python Projects/2015.10.16/Mail Application.py", line 2, in <module>
server = smtplib.SMTP("smtp.gmail.com,587")
File "C:\Python34\lib\smtplib.py", line 242, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python34\lib\smtplib.py", line 321, in connect
self.sock = self._get_socket(host, port, self.timeout)
File "C:\Python34\lib\smtplib.py", line 292, in _get_socket
self.source_address)
File "C:\Python34\lib\socket.py", line 494, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
File "C:\Python34\lib\socket.py", line 533, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11001] getaddrinfo failed
You can also try yagmail :你也可以试试yagmail :
import yagmail
yag = yagmail.SMTP("user@gmail.com", "password")
yag.send("recipient@gmail.com", subject="sub", contents="Test.")
Install using pip install yagmail
.使用
pip install yagmail
。
Lots of more tricks can be found on the github page, such as passwordless script.在 github 页面上可以找到更多技巧,例如无密码脚本。
I think perhaps your problem lies with this:我想也许你的问题在于:
server = smtplib.SMTP("smtp.gmail.com:587")
I've got a few programs that send e-mails, and I use the following format instead:我有一些发送电子邮件的程序,我使用以下格式:
server = smtplib.SMTP("smtp.gmail.com, 587")
If you can't see the difference at first, the colon has been changed to a comma.如果您一开始看不出区别,则冒号已更改为逗号。 Hope this fixes it!
希望这能解决它!
Try this尝试这个
import smtplib
Server=smtplib.SMTP('smtp.gmail.com',587)
Server.starttls()
Server.login("EMAIL_YOUR","YOUR_PASSWORD")
msg="Hello, Its the Message!"
Server.sendmail("whom_2_send@gmail.com","your_email@gmail.com",msg)
print("email send succesfully") #Just for confirmation
Server.quit()
try this:尝试这个:
server = smtplib.SMTP('localhost')
server.set_debuglevel(1)
server.sendmail(email, password, message)
server.quit()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.