0

I have a machine with two domain names, say a.com and b.com.

When I use postfix to send something from an address like [email protected], it replaces it with [email protected] every time. My main.cf file specifies only a.com so I don't know where the b.com is coming from.

Here's the relevant part of maillog... the first line is the intiation of the message and then the 6th line is the one where [email protected] mysteriously pops up.

mymachine sendmail[28543]: qA3NGbOR028543: [email protected], size=792, class=0, nrcpts=1, msgid=<[email protected]>, relay=apache@localhost
mymachine postfix/smtpd[28546]: connect from b.com[127.0.0.1]
mymachine postfix/smtpd[28546]: 912F9758031: client=b.com[127.0.0.1]
mymachine postfix/cleanup[28549]: 912F9758031: message-id=<[email protected]>
mymachine sendmail[28543]: qA3NGbOR028543: [email protected], delay=00:00:00, xdelay=00:00:00, mailer=relay, pri=30792, relay=[127.0.0.1] [127.0.0.1], dsn=2.0.0, stat=Sent (Ok: queued as 912F9758031)
mymachine postfix/qmgr[28527]: 912F9758031: from=<[email protected]>, size=1130, nrcpt=1 (queue active)

I'm not sure if it's relevant how I called this, but it's from some PHP mail() and I've ensured the -f flag is passed along. If any more info might help I'd be happy to deliver it!

1

1 Answer 1

0

Following

http://mail.python.org/pipermail/mailman-developers/2001-March/008476.html

I found it was easier just to uninstall sendmail, install postfix, and use a Python script to send the mail. Here is the Python 3 code which I used to send the message (it needed to be internationalized hence the UTF-8 encodings).

import email.message, email.mime.text, smtplib, sys
from email.utils import parseaddr, formataddr
from email.header import Header
from email.charset import Charset

def format_address(name, email):
    if not name:
        return email
    name = Charset('iso-8859-1').header_encode(name)
    return formataddr((name, email))

def send_unicode_email(mFrom, mTo, mSubject, mBody):
    sender_name, sender_addr = parseaddr(mFrom)
    recipient_name, recipient_addr = parseaddr(mTo)

    composed = email.mime.text.MIMEText(mBody.encode('UTF-8'), _charset='UTF-8')
    composed['from'] = format_address(sender_name, sender_addr)
    composed['to'] = format_address(recipient_name, recipient_addr)
    composed['subject'] = Header(mSubject, 'UTF-8')

    srv = smtplib.SMTP('localhost')
    srv.send_message(composed)
    srv.quit()

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .