Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python smtplib send_message()失败,返回AttributeError:';str';对象没有属性';获得所有';_Python_Email_Attributeerror_Smtplib - Fatal编程技术网

Python smtplib send_message()失败,返回AttributeError:';str';对象没有属性';获得所有';

Python smtplib send_message()失败,返回AttributeError:';str';对象没有属性';获得所有';,python,email,attributeerror,smtplib,Python,Email,Attributeerror,Smtplib,我正在做一个项目,我必须使用Python3.4中的smtplib和email模块来发送电子邮件 我可以创建电子邮件本身,也可以连接到服务器,但它会返回此异常: reply: b'235 2.7.0 Accepted\r\n' reply: retcode (235); Msg: b'2.7.0 Accepted' send: 'QUIT\r\n' reply: b'221 2.0.0 closing connection s66sm8304113yhp.2 - gsmtp\r\n' reply:

我正在做一个项目,我必须使用Python3.4中的smtplib和email模块来发送电子邮件

我可以创建电子邮件本身,也可以连接到服务器,但它会返回此异常:

reply: b'235 2.7.0 Accepted\r\n'
reply: retcode (235); Msg: b'2.7.0 Accepted'
send: 'QUIT\r\n'
reply: b'221 2.0.0 closing connection s66sm8304113yhp.2 - gsmtp\r\n'
reply: retcode (221); Msg: b'2.0.0 closing connection s66sm8304113yhp.2 - gsmtp'
Traceback (most recent call last):
  File "base.py", line 108, in <module>
    send(fromaddr, toaddrs, msg)
  File "base.py", line 61, in send
    server.send_message(fromaddr, toaddrs, msg)
  File "/usr/lib/python3.4/smtplib.py", line 829, in send_message
    resent = msg.get_all('Resent-Date')
AttributeError: 'str' object has no attribute 'get_all'
的签名与不相同。因此,请尝试:

编辑

您还需要将
标题单独添加到:
标题,而不是作为列表:

    for item in input("To: ").split():
        msg['To'] = item

谢谢你指出这一点,我错过了区别。我不再得到那个错误了,但我现在得到了这个错误:
AttributeError:'list'对象没有属性'encode'
。我会用完整的回溯更新我的问题。没关系,我自己就知道了新的错误。这是由
msg['To']=input().split()
行引起的,因为该行接受输入并生成列表。谢谢,接受你的回答。@RPiAwesomeness。是:您需要单独添加每个项目(我已经更新了我的答案)。这节省了我的时间。我真希望这句话在什么地方被明确地说出来。谢谢@ekhumoro!
    server.send_message(msg, fromaddr, toaddrs)
    for item in input("To: ").split():
        msg['To'] = item