zoukankan      html  css  js  c++  java
  • 命名问题: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:.....Pythonlibsmtplib.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.

    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
  • 相关阅读:
    poj 1010
    poj 1060
    poj 1001
    POJ 2769
    POJ 2559
    poj 2403
    POJ 1088
    设置全屏与退出全屏
    iframe 父子页面方法调用
    Web 前端面试小知识
  • 原文地址:https://www.cnblogs.com/qinfei0967/p/9146846.html
Copyright © 2011-2022 走看看