SMTP 错误:(552,'5.6.0 提交被拒绝发件人与发件人不匹配)

发布于 2024-09-26 19:04:22 字数 2278 浏览 1 评论 0原文

我编写了一个 Python 脚本来通过中继服务器发送电子邮件。我已经通过使用 Telnet 发送电子邮件来测试适当的电子邮件地址等是否已获得许可。当设置为通过我的旧中继服务器发送时,我的 Python 脚本也可以工作。

因此,我很困惑为什么会收到以下错误消息:

 (552, '5.6.0 Submission denied Sender does not match originator <myEmailAddress>)

我查看了 SMTP 错误 552,它是由超出邮件大小引起的,但我只发送一封包含几行 html 的电子邮件只有几 kb 大小,所以我假设我可以安全地排除这个问题。

关于可能出现的问题还有其他想法吗?

编辑: 这是生成错误的 Python 代码。

1 #!/usr/bin/env python
  2 import sys
  3 from sys import argv
  4 import smtplib
  5 import logging
  6 import logging.handlers
  7
  8 LOG_FILENAME = 'sendMail.log'
  9 inputMessage = argv[1]
 10 sender = '[email protected]'
 11 receivers = '[email protected]'
 12 #Reads in the file as a single string
 13 message = open(inputMessage, 'r').read()
 14 log = logging.getLogger()
 15
 16 def initializelogging():
 17     log.setLevel(logging.DEBUG)
 18     fileformatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
 19     filehandler = logging.handlers.RotatingFileHandler(
 20                   LOG_FILENAME,
 21                   maxBytes=10000000,
 22                   backupCount=100)
 23     filehandler.setFormatter(fileformatter)
 24     consoleformatter = logging.Formatter('%(levelname)s: %(message)s')
 25     consolehandler = logging.StreamHandler()
 26     consolehandler.setLevel(logging.INFO)
 27     consolehandler.setFormatter(consoleformatter)
 28     log.addHandler(filehandler)
 29     log.addHandler(consolehandler)
 30 initializelogging()
 31
 32 def sendMail():
 33     try:
 34        
 35         smtpObj = smtplib.SMTP('[email protected]')
 36         smtpObj.sendmail(sender,sender, message)
 37         print "Successfully sent email"
 38         log.info('Successfully sent email')
 39     except Exception, err:
 40         log.error('Unable to send email. See below stack trace........')
 41         log.error('%s\n' % str(err))
 42 sendMail()

I've writted a Python script to send emails via a relay server. I've tested that the appropriate email address's etc are permissioned etc by sending an email using Telnet. My Python script also work when set up to send via my old relay server.

Therefore i am confused as to why i am getting the following error message:

 (552, '5.6.0 Submission denied Sender does not match originator <myEmailAddress>)

I've looked at the SMTP error 552 and it is caused by the message size being exceeded, but i am only sending an email containing a few lines of html which is only a few kb in size so i'm assuming i can safely rule this issue out.

Any other ideas as to what could be the issue?

EDIT:
Here is the Python code which generates the error.

1 #!/usr/bin/env python
  2 import sys
  3 from sys import argv
  4 import smtplib
  5 import logging
  6 import logging.handlers
  7
  8 LOG_FILENAME = 'sendMail.log'
  9 inputMessage = argv[1]
 10 sender = '[email protected]'
 11 receivers = '[email protected]'
 12 #Reads in the file as a single string
 13 message = open(inputMessage, 'r').read()
 14 log = logging.getLogger()
 15
 16 def initializelogging():
 17     log.setLevel(logging.DEBUG)
 18     fileformatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
 19     filehandler = logging.handlers.RotatingFileHandler(
 20                   LOG_FILENAME,
 21                   maxBytes=10000000,
 22                   backupCount=100)
 23     filehandler.setFormatter(fileformatter)
 24     consoleformatter = logging.Formatter('%(levelname)s: %(message)s')
 25     consolehandler = logging.StreamHandler()
 26     consolehandler.setLevel(logging.INFO)
 27     consolehandler.setFormatter(consoleformatter)
 28     log.addHandler(filehandler)
 29     log.addHandler(consolehandler)
 30 initializelogging()
 31
 32 def sendMail():
 33     try:
 34        
 35         smtpObj = smtplib.SMTP('[email protected]')
 36         smtpObj.sendmail(sender,sender, message)
 37         print "Successfully sent email"
 38         log.info('Successfully sent email')
 39     except Exception, err:
 40         log.error('Unable to send email. See below stack trace........')
 41         log.error('%s\n' % str(err))
 42 sendMail()

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无声无音无过去 2024-10-03 19:04:22

我无法保证其中任何一个都是错误的实际原因,但是:

  1. 认为您收到的消息可能是说From: 邮件中的标头与您在 sendmail() 调用中使用的发件人电子邮件地址不匹配。确保您从文件 a) 中读取的邮件具有有效的 SMTP 标头(至少 FromToSubject 以及 < code>MIME-Version 和 Content-Type 不会有什么坏处),更具体地说 b) 有一个 From: [email protected] 标头。

  2. SMTP 对象的实例化采用服务器地址,而不是电子邮件地址。您应该使用 smtpObj = smtplib.SMTP('mail.server.com') 或其他没有那么多 @ 的东西。否则,它可能无法连接到您认为的服务器。

I can't guarantee that either of these is the actual cause of the error, but:

  1. I think the message you're getting might be saying that the From: header in your message doesn't match the e-mail address you are using for the sender in the sendmail() call. Make sure that the message you are reading from the file a) has valid SMTP headers (at least From, To, and Subject, and MIME-Version and Content-Type wouldn't hurt) and more specifically b) has a From: [email protected] header.

  2. The instantiation for a SMTP object takes a server address, not an e-mail address. You should be using smtpObj = smtplib.SMTP('mail.server.com') or something else without so much @ in it. Otherwise, it may not be connecting to the server you think it is.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文