本文介绍了如何在不登录服务器的情况下在 Python 中发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在没有登录 Python 服务器的情况下发送电子邮件.我正在使用 Python 3.6.我尝试了一些代码,但收到一个错误.这是我的代码:

I want to send an email without login to server in Python. I am using Python 3.6.I tried some code but received an error. Here is my Code :

import smtplib

smtpServer='smtp.yourdomain.com'
fromAddr='from@Address.com'
toAddr='to@Address.com'
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 和密码,但会收到错误消息:

I expect the mail should be sent without asking user id and password but getting an error :

"smtplib.SMTPSenderRefused: (530, b'5.7.1 客户端未通过身份验证', 'from@Address.com')"

推荐答案

下面的代码对我有用.首先,我通过网络团队打开/启用了端口 25,并在程序中使用它.

The code below worked for me.First, I opened/enabled Port 25 through Network Team and used it in the program.

import smtplib
smtpServer='smtp.yourdomain.com'
fromAddr='from@Address.com'
toAddr='to@Address.com'
text= "This is a test of sending email from within Python."
server = smtplib.SMTP(smtpServer,25)
server.ehlo()
server.starttls()
server.sendmail(fromAddr, toAddr, text)
server.quit()

这篇关于如何在不登录服务器的情况下在 Python 中发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-05 01:30