def send_and_save_common_message(self, subject, body, to): try: m = Message(account=self.exchangelib_connection, folder=a.sent, subject=subject, body=body, to_recipients=to) m.send_and_save() print('Your message send success!') except Exception: print('Please try again!')
def send_with_attachment(self, subject, body, to, path, cc): if os.path.exists(path): try: item = Message(account=self.exchangelib_connection, folder=a.sent, subject=subject, body=body, to_recipients=to, cc_recipients=cc) with open(path, 'rb') as f: binary_file_content = f.read() my_file = FileAttachment(name=os.path.basename(path), content=binary_file_content) item.attach(my_file) item.save() item.send_and_save() print('Your message send success!') except Exception: print('Please try again!') else: print('Please check your path')