命名问题:module 'yagmail' has no attribute 'SMTP'

我们在命名文件名的时候,应该避免跟系统包名字重合。
转载自:https://stackoverflow.com/questions/16512256/no-attribute-smtp-error-when-trying-to-send-email-in-python

I am trying to send an email in Python:

import smtplib


fromaddr = '......................'  
toaddrs  = '......................'  
msg = 'Spam email Test'  

username = '.......'  
password = '.......'

server = smtplib.SMTP('smtp.gmail.com', 587)  
server.ehlo()
server.starttls()
server.login(username, password)  
server.sendmail(fromaddr, toaddrs, msg)  
server.quit()

I understand that this is probably not the correct message format.

Anyways, I get an error:

C:\.....>python email.py
Traceback (most recent call last):
  File "email.py", line 1, in <module>
    import smtplib
  File "C:\.....\Python\lib\smtplib.py", line 47,
 in <module>
    import email.utils
  File "C:\.....\email.py", line 15, in
<module>
    server = smtplib.SMTP('smtp.gmail.com', 587)
AttributeError: 'module' object has no attribute 'SMTP'

I don't quite understand what I am doing wrong here... Anything incorrect?

NOTE: All the periods are replacements for password/email/file paths/etc.

1 Answer

up vote 48down voteaccepted

Python already has an email module. Your script's name is email.py, which is preventing smtplib from importing the built-in email module.

Rename your script to something other than email.py and the problem will go away.

  • 8
    Also, remember to (re)move the pyc file. – RandomInsano Dec 30 '13 at 21:18

 

转载于:https://www.cnblogs.com/qinfei0967/p/9146846.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值