繁体   English   中英

使用python发送电子邮件仅在shell中有效

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM