![](/img/trans.png)
[英]How to maintain mail conversion (reply / forward / reply to all like gmail) of email using Python pop/imap lib?
[英]How to gmail like forward email?
有没有办法使用smtp转发电子邮件(类似gmail的邮件,您知道...,下面还有其他文本)? 这是我的一段代码:
def forward_email(email_id, email_to):
client, messages = get_original_email(email_id)
typ, data = client.fetch(messages[0].split(' ')[-1], '(RFC822)')
email_data = data[0][1]
message = email.message_from_string(email_data)
smtp = smtplib.SMTP(EMAIL_HOST, EMAIL_PORT)
smtp.ehlo()
smtp.starttls()
smtp.login(IMAP_LOGIN, IMAP_PASSWORD)
result = smtp.sendmail(email.utils.parseaddr(message['From']),
email_to, message.as_string())
smtp.quit()
return result
现在它不起作用,因为message.as_string()具有特殊的标头和其他未使用的信息。 我猜gmail阻止了它,因为这。
下面的代码为我正确地工作,甚至在函数调用时连续发送邮件
def send_email(to='example@email.com', f_host='send.one.com', f_port=587, f_user='from@me.com', f_passwd='my_pass', subject='subject for email', message='content message'):
smtpserver = smtplib.SMTP(f_host, f_port)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(f_user, f_passwd) # from email credentialssssssssss
header = 'To:' + to + '\n' + 'From: ' + f_user + '\n' + 'Subject:' + subject + '\n'
message = header + '\n' + message + '\n\n'
smtpserver.sendmail(f_user, to, str(message))
smtpserver.close()
DBG('Mail is sent successfully!!')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.