2017-04-19 79 views
0

我的代碼:如何使用中的smtplib蟒蛇發送電子郵件

import smtplib 

try: 
    mail = smtplib.SMTP('smtp.gmail.com', 587) 
    print("Connection successful") 
except: 
    print("Connection failed") 

content = str(input("Your message: ")) 

senderLogin = str(input('Your full email (currently only GMail): ')) 
senderPass = str(input('Your password(data is not stored): ')) 

receiverAcc = str(input('Who would you like to send it to: ')) 

mail.ehlo() 
mail.starttls() 
mail.ehlo 

mail.login(senderLogin, senderPass) 
try: 
    mail.sendmail(senderLogin, receiverAcc, content) 
    print ("Email sent") 

except: 
    print('error') 

mail.close() 

我無法得到它的工作。所發生的只是彈出的外殼,它是一個空白的屏幕。沒有其他的。如果任何人能夠澄清和/或幫助,那會很好。另外,我已經在我的Google帳戶中啓用了安全性較低的應用。

UPDATE

我與端口發揮各地,並發現25端口smtp.gmail.com工作。

+0

你的輸出是什麼? –

回答

0

有可能您被Google的SMTP服務器阻止。您應該嘗試使用不同的SMTP服務器,並根據需要調整mail.starttls()的使用情況。否則,你的代碼應該工作。

相關問題