I am working on setting up a script that sends incoming mail to the recipient list.
Here is what I have now:
I read the email from stdin (this is how postfix passes it):
email_in = sys.stdin.read() incoming = Parser().parse(email_in) sender = incoming['from'] this_address = incoming['to']
I am testing for multipart:
if incoming.is_multipart(): for payload in incoming.get_payload(): # if payload.is_multipart(): ... body = payload.get_payload() else: body = incoming.get_payload(decode=True)`
I installed the outgoing message:
msg = MIMEMultipart() msg['Subject'] = incoming['subject'] msg['From'] = this_address msg['reply-to'] = sender msg['To'] = " foo@bar.com " msg.attach(MIMEText(body.encode('utf-8'), 'html', _charset='UTF-8')) s = smtplib.SMTP('localhost') s.send_message(msg) s.quit()
This works well with ASCII characters (English text), forwards it all.
When I send non-ascii characters, it returns gibberish (depending on bytes of the mail client or ascf-representations of utf-8 characters)
What could be the problem? Is it on the inbound or outbound side?
source share