Я хочу создать скрипт Python для автоматического ответа на html почту из канала postfix:
Пример в файле псевдонимов:
testmail: "| python /opt/script/autoreply.py /opt/script/autoreply.html"
Файл autoreply.html будет содержать html-письмо.
Вот пример из python:
https://docs.python.org/2/library/email-examples.html#id5
для отправки альтернативного MIMEMultipart
Я хочу использовать этот пример для моего сценария. Идея в том, чтобы загрузить файл autoreply.html.
#!/usr/bin/env python
#autoreply.py
import smtplib
import sys
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# me == my email address
# you == recipient's email address
me = "my@email.com"
you = "you@email.com"
# Create message container - the correct MIME type is multipart/alternative.
msg = MIMEMultipart('alternative')
msg['Subject'] = "Link"
msg['From'] = me
msg['To'] = you
# Create the body of the message (a plain-text and an HTML version).
text = open(sys.argv[1], 'r')
html = open(sys.argv[2], 'r')
# Record the MIME types of both parts - text/plain and text/html.
part1 = MIMEText(text.read(), 'plain')
text.close()
part2 = MIMEText(html.read(), 'html')
html.close()
# Attach parts into message container.
# According to RFC 2046, the last part of a multipart message, in this case
# the HTML message, is best and preferred.
msg.attach(part1)
msg.attach(part2)
# Send the message via local SMTP server.
s = smtplib.SMTP('smtprelay.gameloft.org')
# sendmail function takes 3 arguments: sender's address, recipient's address
# and message to send - here it is sent as one string.
s.sendmail(me, you, msg.as_string())
s.quit()
как я могу отредактировать этот скрипт, чтобы канал мог отправлять html (autoreply.html) электронную почту? Измените адрес отправителя на адрес из исходного сообщения, загрузите файл autoreply.html.
Если файл autoreply.txt отсутствует, загрузите файл autoreply.html по умолчанию. (для примера из python нужен текст / plain)
Может ли кто-нибудь мне помочь? Это довольно сложно для меня.
Спасибо!