2015-10-18 227 views
0

我試圖使用SMTP在Python 3.4來發送電子郵件,但我收到以下錯誤,當我運行代碼:錯誤發送使用Gmail SMTP電子郵件(Python 3中)

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. 

這裏是我的代碼:

import smtplib 
server = smtplib.SMTP("smtp.gmail.com:587") 

user_email = "[email protected]" 
user_password = "password" 
recipient_email = "[email protected]" 
msg = "Test." 

server.login(user_email, user_password) 

server.ehlo() 
server.starttls() 
server.sendmail(user_email, recipient_email, msg) 
server.quit() 

謝謝。

編輯:

我已經改變了第二行server = smtplib.SMTP("smpt.gmail.com, 587")的建議。這似乎修復錯誤,但現在我得到一個新問題:

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 

回答

0

我想也許你的問題就在於這一點:
server = smtplib.SMTP("smtp.gmail.com:587")

我已經得到了發送電子郵件的幾個方案,並且我使用以下格式代替:
server = smtplib.SMTP("smtp.gmail.com, 587")

如果您在開始時看不到區別,則冒號已更改爲逗號。 希望這能解決它!

0

您也可以嘗試yagmail

import yagmail 
yag = yagmail.SMTP("[email protected]", "password") 
yag.send("[email protected]", subject="sub", contents="Test.") 

安裝使用pip install yagmail

很多更多的技巧可以在github頁面找到,比如無密碼腳本。

1

我可以幫忙。

  1. 請參閱here並打開。

然後

server = smtplib.SMTP("smtp.gmail.com, 587") 
server.starttls() 
server.login("username","p455w0rd") 
0

試試這個

import smtplib 
Server=smtplib.SMTP('smtp.gmail.com',587) 
Server.starttls() 
Server.login("EMAIL_YOUR","YOUR_PASSWORD") 
msg="Hello, Its the Message!" 
Server.sendmail("[email protected]","[email protected]",msg) 
print("email send succesfully") #Just for confirmation 
Server.quit() 
相關問題