使用python发送电子邮件仅在shell中有效
我真的不知道这段代码是否只在我尝试运行脚本时才给我一个错误,但在我从shell执行脚本时才起作用 testingmail.py使用python发送电子邮件仅在shell中有效,python,shell,Python,Shell,我真的不知道这段代码是否只在我尝试运行脚本时才给我一个错误,但在我从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' bo
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中的同一文件夹或目录中不添加任何名为模块的文件
感谢您的支持当它不工作时,您如何运行它?您如何通过shell运行它?我尝试运行python shell,它可以工作,但当我决定将脚本复制到文件中并通过python testingmail.py运行它时。它显示了一个错误@Grimmy@SamChats我在那里重写了它。您是否有一个名为smtplib.py的脚本,它可能与testingmail.py位于同一目录下?