#!/usr/bin/env python from email.MIMEText import MIMEText from email.MIMEMultipart import MIMEMultipart import os # This script creates two messages and pipes them each to procmail. # It assumes procmail is configured to deliver mail to an MBOX-format mail # spool. # Upon reading that mail spool with /bin/mail, only the first message is # visible; the second message appears to be a part of the first. # This is because Message.as_string() does not include a trailing newline # at the end of the last line of the generate message. def main(): msg1 = MIMEMultipart() msg1.attach(MIMEText('part #1')) msg1.attach(MIMEText('part #2')) msg1['Subject'] = 'Test 1' print 'Message #1:', `msg1.as_string()` p = os.popen('procmail -f -', 'w') p.write(msg1.as_string()) p.close() msg2 = MIMEText('test #2') msg2['Subject'] = 'Test 2' print 'Message #2:', `msg2.as_string()` p = os.popen('procmail -f -', 'w') p.write(msg2.as_string()) p.close() if __name__ == '__main__': main()