[英]Sending an E-mail using python works only in shell
我真的不知道這段代碼僅在嘗試運行腳本時才給我一個錯誤,但是當我從外殼執行該腳本時卻能給我一個錯誤。
testingmail.py
import smtplib
DEBUG = TRUE
to = 'receiver@hotmail.com'
subject = 'Sending an E-mail using python'
text = 'here is the message'
sender = 'someone@gmail.com'
password = 'password'
body = '\r\n'.join([
'To: %s' % to,
'From: %s' % sender,
'Subject: %s' % subject,
'',
text
])
try:
server = smtplib.SMTP('smtp.gmail.com', 587)
server.ehlo()
server.starttls()
server.login(sender, password)
server.sendmail(sender, [to], body)
print('E-mail Sent!')
except:
print('Error sending E-mail')
錯誤是:smtplib沒有屬性SMTP。 我發現的所有結果都表明,文件名干擾了python中的電子郵件模塊,這是錯誤的,但沒有任何反應
答案是確保不要在我的示例email.py
的同一文件夾或目錄中添加任何名為模塊的文件。
謝謝你的支持
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.