Sending email to a Microsoft Exchange group using Python?

I wrote a python script to send emails, but now I am wondering if it is possible to send emails to Microsoft exchange groups using python? I tried to include the group in cc and in the fields, but that doesn't seem like a trick. It is displayed, but does not seem to correspond to a group of letters; it is just text.

Does anyone know if this is possible?

+4
source share
1 answer

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

import smtplib from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart address_book = [' person1@company.com ', ' person2@company.com ', ' group3@company.com '] msg = MIMEMultipart() sender = ' me@company.com ' 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() 
+9
source

Source: https://habr.com/ru/post/1484882/


All Articles