我想在没有登录到Python的服务器的情况下发送电子邮件。我使用的是Python 3.6。我尝试了一些代码,但收到了错误。这是我的代码:
import smtplib
smtpServer='smtp.yourdomain.com'
fromAddr='[email protected]'
toAddr='[email protected]'
text= "This is a test of sending email from within Python."
server = smtplib.SMTP(smtpServer)
server.set_debuglevel(1)
server.sendmail(fromAddr, toAddr, text)
server.quit()
我希望在不询问用户ID和密码的情况下发送邮件,但收到错误:
“smtplib.SMTPSenderRefused:(530,b'5.7.1客户端未经过身份验证','from @Address.com')”
下面的代码对我有用。首先,我通过网络团队打开/启用了端口25并在程序中使用。
import smtplib
smtpServer='smtp.yourdomain.com'
fromAddr='[email protected]'
toAddr='[email protected]'
text= "This is a test of sending email from within Python."
server = smtplib.SMTP(smtpServer,25)
s.ehlo()
s.starttls()
server.sendmail(fromAddr, toAddr, text)
server.quit()