使用 Python 向 Microsoft Exchange 组发送电子邮件?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16968758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 00:07:02  来源:igfitidea点击:

Sending Email to a Microsoft Exchange group using Python?

pythonsmtplib

提问by Ethan

I've written a python script to send out emails, but now I'm wondering if it's possible to send emails to Microsoft exchange groups using python? I've tried including the group in the cc and to fields but that doesn't seem to do the trick. It shows up, but doesn't seem to correspond to a group of emails; it's just plain text.

我已经编写了一个 python 脚本来发送电子邮件,但现在我想知道是否可以使用 python 向 Microsoft 交换组发送电子邮件?我试过将组包含在 cc 和 to 字段中,但这似乎不起作用。它出现了,但似乎并不对应一组电子邮件;它只是纯文本。

Anyone know if this is possible?

有谁知道这是否可能?

采纳答案by jsucsy

This is definitely possible. Your exchange server should recognize it if you treat it as a full address. For example if you want to send it to person1, person2, and group3, use the following:

这绝对是可能的。如果您将其视为完整地址,则您的交换服务器应该能够识别它。例如,如果要将其发送给 person1、person2 和 group3,请使用以下命令:

import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart

address_book = ['[email protected]', '[email protected]', '[email protected]']
msg = MIMEMultipart()    
sender = '[email protected]'
subject = "My subject"
body = "This is my email body"

msg['From'] = sender
msg['To'] = ','.join(address_book)
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
text=msg.as_string()
#print text
# Send the message via our SMTP server
s = smtplib.SMTP('our.exchangeserver.com')
s.sendmail(sender,address_book, text)
s.quit()