SMTP ERROR: (552, '5.6.0 Submission denied Sender does not match originator <myEmailAddress>)
-
29-09-2019 - |
Question
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 = 'hi@sender.com'
11 receivers = 'hi@sender.com'
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('mailserver@server.com')
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()
Solution
I can't guarantee that either of these is the actual cause of the error, but:
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 thesendmail()
call. Make sure that the message you are reading from the file a) has valid SMTP headers (at leastFrom
,To
, andSubject
, andMIME-Version
andContent-Type
wouldn't hurt) and more specifically b) has aFrom: hi@sender.com
header.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.