Я хочу отвечать на письма с помощью скрипта Python, и ответное письмо должно содержать исходное письмо в конце
replyMsg = MIMEMultipart('alternative')
replyMsg['Message-ID'] = make_msgid()
replyMsg['References'] = replyMsg['In-Reply-To'] = self.selectedMessage['Message-ID']
replyMsg['Subject'] = 'Re: ' + self.selectedMessage['Subject']
replyMsg['Reply-To'] = _MAIL_REPLY_TO
replyMsg['From'] = _MAIL_USER
sendTo = ''
if self.selectedMessage['Reply-to']:
sendTo = self.selectedMessage['Reply-To']
else:
sendTo = self.selectedMessage['From']
if self.selectedMessage['CC'] != sendTo:
replyMsg['CC'] = self.selectedMessage['CC']
replyMsg.attach(MIMEText(dedent(body), 'plain'))
replyMsg.attach(MIMEText(bodyHtml, 'html'))
replyMsg.attach(MIMEMessage(self.selectedMessage))