如何解决在一个线程中发送自动消息
我正在尝试通过python发送每周电子邮件(Outlook)。有没有一种方法可以将主题相似/主题相同但内容不同的那些电子邮件编译到一个电子邮件线程中?
我听说这个想法是将电子邮件固定到一个固定的message_id
上。但这对我不起作用。
def send_email(email_recipient,email_subject,email_message,attachment_location = '',email_cc = ''):
email_sender = 'my_email@gmail.com'
msg = MIMEMultipart()
msg['From'] = email_sender
msg['To'] = email_recipient
msg['Cc'] = email_cc
msg['Subject'] = email_subject
msg.attach(MIMEText(email_message,'plain'))
# Create thread
my_id = make_msgid()
msg["Message-ID"] = my_id
msg["In-Reply-To"] = my_id
msg["References"] = my_id
#
if attachment_location != '':
filename = os.path.basename(attachment_location)
attachment = open(attachment_location,"rb")
part = MIMEBase('application','octet-stream')
part.set_payload(attachment.read())
encoders.encode_base64(part)
part.add_header('Content-Disposition',"attachment; filename= %s" % filename)
msg.attach(part)
try:
server = smtplib.SMTP('smtp.office365.com',587)
server.ehlo()
server.starttls()
server.login('my_email@gmail.com','my_password')
text = msg.as_string()
server.sendmail(email_sender,email_recipient,text)
print('email sent')
server.quit()
except:
print("SMPT server connection error")
return True
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。