def send_email(self, body=None, subject=None, to=list, cc=None, bcc=None, send_as=None, attachments=None): """Sends an email in one method, a shortcut for creating an instance of :class:`Message <pyOutlook.core.message.Message>` . Args: body (str): The body of the email subject (str): The subject of the email to (list): A list of :class:`Contacts <pyOutlook.core.contact.Contact>` cc (list): A list of :class:`Contacts <pyOutlook.core.contact.Contact>` which will be added to the 'Carbon Copy' line bcc (list): A list of :class:`Contacts <pyOutlook.core.contact.Contact>` while be blindly added to the email send_as (Contact): A :class:`Contact <pyOutlook.core.contact.Contact>` whose email the OutlookAccount has access to attachments (list): A list of dictionaries with two parts [1] 'name' - a string which will become the file's name [2] 'bytes' - the bytes of the file. """ email = Message(self, body, subject, to, cc=cc, bcc=bcc, sender=send_as,) if attachments is not None: for attachment in attachments: email.attach(attachment.get('bytes'), attachment.get('name')) email.send()
def test_message_sent_with_contact_recipients(self): """ A list of strings or Contacts can be provided as the To/CC/BCC recipients """ mock_post = Mock() mock_post.status_code = 200 self.mock_post.return_value = mock_post message = Message(self.account, '', '', [Contact('*****@*****.**')]) message.send()
def test_is_read_status(self): """ Test that the correct value is returned after changing the is_read status """ mock_patch = Mock() mock_patch.status_code = 200 self.mock_patch.return_value = mock_patch message = Message(self.account, 'test body', 'test subject', [], is_read=False) message.is_read = True self.assertTrue(message.is_read)
def test_category_added(self): """ Test that Message.categories is updated in addition to the API call made """ mock_patch = Mock() mock_patch.status_code = 200 self.mock_patch.return_value = mock_patch message = Message(self.account, 'test body', 'test subject', [], categories=['A']) message.add_category('B') self.assertIn('A', message.categories) self.assertIn('B', message.categories)
def new_email(self, body='', subject='', to=list): """Creates a :class:`Message <pyOutlook.core.message.Message>` object. Keyword Args: body (str): The body of the email subject (str): The subject of the email to (List[Contact]): A list of recipients to email Returns: :class:`Message <pyOutlook.core.message.Message>` """ return Message(self, body, subject, to)
def new_email(self, body='', subject='', to=list, sender=None, cc=None, bcc=None): """Creates a :class:`Message <pyOutlook.core.message.Message>` object. Keyword Args: body (str): The body of the email subject (str): The subject of the email to (List[Contact]): A list of recipients to email Returns: :class:`Message <pyOutlook.core.message.Message>` """ return Message(self.access_token, body, subject, to, sender=sender, cc=cc, bcc=bcc)
def test_attachments_added(self): """ Test that attachments are added to Message in the correct format """ message = Message(self.account, '', '', []) message.attach('abc', 'Test/Attachment.csv') message.attach(b'some bytes', 'attached.pdf') self.assertEqual(len(message._attachments), 2) file_bytes = [attachment._content for attachment in message._attachments] file_names = [attachment.name for attachment in message._attachments] # The files are base64'd for the API some_bytes = base64.b64encode(b'some bytes') abc = base64.b64encode(b'abc') self.assertIn(some_bytes.decode('UTF-8'), file_bytes) self.assertIn(abc.decode('UTF-8'), file_bytes) self.assertIn('TestAttachment.csv', file_names)