我正在尝试使用python发送电子邮件并收到错误。这是我的代码:
socket
这是我不断得到的错误
import smtplib
server = smtplib.SMTP('smtp.gmail.com', 465)
server.login("someone@gmail.com", "pass")
msg = "Hello!"
server.sendmail("someone@gmail.com", "someone@gmail.com", msg)
print("Sent")
我做错了什么?
答案 0 :(得分:2)
在email.py
中,导入应为:
from email.mime.multipart import smtplib
或者可能:
import smtplib
from email.mime.multipart import [...]
答案 1 :(得分:2)
您有一个脚本<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"
xmlns:cs="urn://Ocpp/Cs/2012/06/"
xmlns:wsa="http://www.w3.org/2005/08/addressing">
<soap:Header>
<cs:chargeBoxIdentity soap:mustUnderstand="true">XXX01</cs:chargeBoxIdentity>
<wsa:Action soap:mustUnderstand="true">/Authorize</wsa:Action>
<wsa:MessageID>123</wsa:MessageID>
<wsa:From><wsa:Address>http://from-endpoint</wsa:Address></wsa:From>
<wsa:ReplyTo soap:mustUnderstand="true"><wsa:Address>http://www.w3.org/2005/08/addressing/anonymous</wsa:Address></wsa:ReplyTo>
<wsa:To soap:mustUnderstand="true"><wsa:Address>http://to-endpoint</wsa:Address></wsa:To>
</soap:Header>
<soap:Body>
<cs:authorizeRequest>
<cs:idTag>1234567</cs:idTag>
</cs:authorizeRequest>
</soap:Body>
</soap:Envelope>
,可以从stdlib中隐藏email个包。重命名脚本。
将来要避免使用stdlib已经采用的脚本名称。特别要避免test.py! : - )
答案 2 :(得分:1)