I've read on how to forward an email using imaplib and stmplib. I grab these emails (have attachments) off of gmail, sort them and want to forward them to another email account.
My code is here, and looks very similar:
message.mail.replace_header("From", from_addresses)
message.mail.replace_header("To", to_addresses)
server = smtplib.SMTP('smtp.gmail.com:587')
server.ehlo()
server.starttls()
server.login(settings.RECEIPTS_EMAIL_ACCOUNT, settings.RECEIPTS_EMAIL_PASSWORD)
server.sendmail(from_addresses, to_addresses, message.mail.as_string())
server.close()
However, whenever it hits the sendmail
line on message.mail.as_string()
, the mail, then it crashes with
*** AttributeError: 'list' object has no attribute 'encode'
How can I convert this to something I can send through imaplib?