There is currently a lot of guessing about the problem, and that is because your system is unable to send you the failure email to explain exactly what the problem is. I ran into a similar problem a while back, was overwhelmed by trying to set up an actual mail system, so wrote a short mail forwarding sendmail stand-in: pygeon_mail
:
#!/usr/bin/python
from __future__ import with_statement
from email.mime.text import MIMEText
import email
import os
import pwd
import smtplib
import stat
import sys
import syslog
import traceback
CONFIG = '/etc/pygeon_mail.rc'
# example config file
#
# server=mail.example.com
# port=25
# domain=example.com
# host=this_pc_host_name
# root=me@example.com,you@example.com
# ethan=me@example.com
# debug=debug@example.com
def check_dangerously_writable(filename):
"return the bits of group/other that are writable"
mode = stat.S_IMODE(os.stat(filename)[0]) # get the mode bits
if mode & (stat.S_IWGRP | stat.S_IWOTH): # zero means not set
syslog.syslog("%s must only be writable by root, aborting" % (filename, ))
sys.exit(1)
def get_config(filename, config=None):
"return settings from config file"
check_dangerously_writable(filename)
if config is None:
config = {}
with open(filename) as settings:
for line in settings:
line = line.strip()
if line and line[:1] != '#':
key, value = line.split('=')
key, value = key.strip(), value.strip()
config[key] = value
return config
def mail(server, port, sender, receiver, subject, message):
"""sends email.message to server:port
receiver is a list of addresses
"""
msg = MIMEText(message.get_payload())
for address in receiver:
msg['To'] = address
msg['From'] = sender
msg['Subject'] = subject
for header, value in message.items():
if header in ('To','From', 'Subject'):
continue
msg[header] = value
smtp = smtplib.SMTP(server, port)
try:
send_errs = smtp.sendmail(msg['From'], receiver, msg.as_string())
except smtplib.SMTPRecipientsRefused as exc:
send_errs = exc.recipients
smtp.quit()
if send_errs:
errs = {}
for user in send_errs:
if '@' not in user:
errs[user] = [send_errs[user]]
continue
server = 'mail.' + user.split('@')[1]
smtp = smtplib.SMTP(server, 25)
try:
smtp.sendmail(msg['From'], [user], msg.as_string())
except smtplib.SMTPRecipientsRefused as exc:
if send_errs[user] != exc.recipients[user]:
errs[user] = [send_errs[user], exc.recipients[user]]
else:
errs[user] = [send_errs[user]]
smtp.quit()
for user, errors in errs.items():
for code, response in errors:
syslog.syslog('%s --> %s: %s' % (user, code, response))
return errs
if __name__ == '__main__':
syslog.openlog('pygeon', syslog.LOG_PID)
try:
config = get_config(CONFIG)
root = config.get('root')
domain = config.get('domain', '')
if domain:
domain = '@' + domain
sender = None
receiver = []
dot_equals_blank = False
ignore_rest = False
next_arg_is_subject = False
redirect = False
subject = ''
for i, arg in enumerate(sys.argv[1:]):
if next_arg_is_subject:
subject = arg
next_arg_is_subject = False
sys.argv[i] = '"%s"' % (arg, )
elif arg == '-s':
next_arg_is_subject = True
elif arg == '-i':
dot_equals_blank = True
elif arg[:2] == '-F':
sender = arg[2:]
elif arg[0] != '-':
receiver.append(arg)
else:
pass
command_line = ' '.join(sys.argv)
if sender is None:
sender = pwd.getpwuid(os.getuid()).pw_name
sender = '%s@%s' % (sender, config['host'])
if not receiver:
receiver.append(pwd.getpwuid(os.getuid()).pw_name)
limit = len(receiver)
for i, target in enumerate(receiver):
if i == limit:
break
if '@' not in target:
receiver[i] = ''
receiver.extend(config.get(target, target+domain).split(','))
receiver = [r for r in receiver if r]
server = config['server']
port = int(config['port'])
all_data = []
text = []
while True:
data = sys.stdin.read()
if not data:
break
all_data.append(data)
if ignore_rest:
continue
for line in data.split('\n'):
if line == '.':
if dot_equals_blank:
line = ''
else:
ignore_rest = True
break
text.append(line)
text = '\n'.join(text)
message = email.message_from_string(text)
errs = mail(server, port, sender, receiver, subject, message)
except Exception:
exc, err, tb = sys.exc_info()
lines = traceback.format_list(traceback.extract_tb(tb))
syslog.syslog('Traceback (most recent call last):')
for line in lines:
for ln in line.rstrip().split('\n'):
syslog.syslog(ln)
syslog.syslog('%s: %s' % (exc.__name__, err))
sys.exit(1)
else:
receiver = []
debug_email = config.get('debug', None)
if debug_email:
receiver.append(debug_email)
if errs and root not in receiver:
receiver.append(root)
if receiver:
debug = [
'command line:',
'-------------',
repr(command_line),
'-' * 79,
'',
'sent email:',
'-----------',
text,
'-' * 79,
'',
'raw data:',
'---------',
''
]
all_data = ''.join(all_data)
while all_data:
debug_text, all_data = repr(all_data[:79]), all_data[79:]
debug.append(debug_text)
debug.append('-' * 79)
if errs:
debug.extend([
'',
'errors:',
'-------',
])
for address, error in sorted(errs.items()):
debug.append('%r: %r' % (address, error))
debug.append('-' * 79)
text = '\n'.join(debug)
message = email.message_from_string(text)
mail(server, port, 'debug@%s' % config['host'], receiver, subject+' [pygeon_mail debugging info]', message)
if errs:
sys.exit(1)
It was written for Python 2.5 and should work with 2.6 and 2.7.
It needs to be copied to /usr/sbin/sendmail
with permissions of 0755 and owned by root:
sudo cp pygeon_mail /usr/sbin/sendmail
sudo chown root:root /usr/sbin/sendmail
sudo chmod 0755 /usr/sbin/sendmail
You need to create an /etc/pygeon_mail.rc
config file (see code for an example).
You can then test it with something like:
$ echo some useful info | sendmail myself -s "some important subject"
and you will hopefully see that email in your normal email account (which you set up in the /etc/pygeon_mail.rc
file).
After that, you should be able to get the actual error, and we can actually help you