0

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()
matt2010
  • 55
  • 10
  • We really need to see some code. – kindall Oct 12 '10 at 14:01
  • We also really need to see the entire bounce message output. It's not clear from your post whether the 552 is being returned by the immediate mail server (server.com) or the ultimate destination (sender.com). – Jim Garrison Oct 12 '10 at 15:52

1 Answers1

0

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: hi@sender.com 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.

kindall
  • 178,883
  • 35
  • 278
  • 309
  • Thanks alot, it was that the from header didn't match the email address i was using for the sender in sendmail()!!! – matt2010 Oct 13 '10 at 08:23