Mailbox ======= Mailbox groups the functionality of both the messages and the email folders. These are the scopes needed to work with the ``MailBox`` and ``Message`` classes. ========================= ======================================= ====================================== Raw Scope Included in Scope Helper Description ========================= ======================================= ====================================== Mail.Read mailbox To only read my mailbox Mail.Read.Shared mailbox_shared To only read another user / shared mailboxes Mail.Send message_send, message_all To only send message Mail.Send.Shared message_send_shared, message_all_shared To only send message as another user / shared mailbox Mail.ReadWrite message_all To read and save messages in my mailbox MailboxSettings.ReadWrite mailbox_settings To read and write user mailbox settings ========================= ======================================= ====================================== .. Useful Methods .. ^^^^^^^^^^^^^^^^^^^^^^^^^ .. `get_folder()` and `get_folders()` are useful to fetch folders that are available under the current instance .. Get Single Folder .. """"""""""""""""" .. **Using Name** .. Using name to get a folder will only search the folders directly under the current folder or root .. .. code-block:: python .. # By Name - Will only find direct child folder .. mail_folder = mailbox.get_folder(folder_name='Todo') .. # By Name - If Todo folder is under Inbox folder .. mail_folder = (mailbox.get_folder(folder_name='Inbox') .. .get_folder(folder_name='Todo')) .. **Using ID** .. As opposed to getting folder by name, using the id you can fetch folder from any child .. .. code-block:: python .. # Assuming we are getting folder Todo under Inbox .. mail_folder = mailbox.get_folder(folder_id='some_id_you_may_have_obtained') .. **Well Known Folders** .. There are few well know folders like **Inbox**, **Drafts**, etc.. .. As they are generally used we have added functions to quickly access them .. .. code-block:: python .. # Inbox .. mail_folder = mailbox.inbox_folder() .. # DeletedItems .. mail_folder = mailbox.deleted_folder() .. # Drafts .. mail_folder = mailbox.drafts_folder() .. # Junk .. mail_folder = mailbox.junk_folder() .. # Outbox .. mail_folder = mailbox.outbox_folder() .. Get Child Folders .. """"""""""""""""" .. **All or Some Child Folders** .. .. code-block:: python .. # All child folders under root .. mail_folders = mailbox.get_folders() .. # All child folders under Inbox .. mail_folders = mailbox.inbox_folder().get_folders() .. # Limit the number or results, will get the top x results .. mail_folders = mailbox.get_folders(limit=7) .. **Filter the results** .. Query is a class available, that lets you filter results .. .. code-block:: python .. # All child folders whose name startswith 'Top' .. mail_folders = mailbox.get_folders(query=mailbox.new_query('displayName').startswith('Top')) Mailbox and Messages """""""""""""""""""" .. code-block:: python mailbox = account.mailbox() inbox = mailbox.inbox_folder() for message in inbox.get_messages(): print(message) sent_folder = mailbox.sent_folder() for message in sent_folder.get_messages(): print(message) m = mailbox.new_message() m.to.add('to_example@example.com') m.body = 'George Best quote: In 1969 I gave up women and alcohol - it was the worst 20 minutes of my life.' m.save_draft() Email Folder """""""""""" Represents a Folder within your email mailbox. You can get any folder in your mailbox by requesting child folders or filtering by name. .. code-block:: python mailbox = account.mailbox() archive = mailbox.get_folder(folder_name='archive') # get a folder with 'archive' name child_folders = archive.get_folders(25) # get at most 25 child folders of 'archive' folder for folder in child_folders: print(folder.name, folder.parent_id) new_folder = archive.create_child_folder('George Best Quotes') Message """"""" **An email object with all its data and methods** Creating a draft message is as easy as this: .. code-block:: python message = mailbox.new_message() message.to.add(['example1@example.com', 'example2@example.com']) message.sender.address = 'my_shared_account@example.com' # changing the from address message.body = 'George Best quote: I might go to Alcoholics Anonymous, but I think it would be difficult for me to remain anonymous' message.attachments.add('george_best_quotes.txt') message.save_draft() # save the message on the cloud as a draft in the drafts folder **Working with saved emails is also easy** .. code-block:: python query = mailbox.new_query().on_attribute('subject').contains('george best') # see Query object in Utils messages = mailbox.get_messages(limit=25, query=query) message = messages[0] # get the first one message.mark_as_read() reply_msg = message.reply() if 'example@example.com' in reply_msg.to: # magic methods implemented reply_msg.body = 'George Best quote: I spent a lot of money on booze, birds and fast cars. The rest I just squandered.' else: reply_msg.body = 'George Best quote: I used to go missing a lot... Miss Canada, Miss United Kingdom, Miss World.' reply_msg.send() **Sending Inline Images** You can send inline images by doing this: .. code-block:: python # ... msg = account.new_message() msg.to.add('george@best.com') msg.attachments.add('my_image.png') att = msg.attachments[0] # get the attachment object # this is super important for this to work. att.is_inline = True att.content_id = 'image.png' # notice we insert an image tag with source to: "cid:{content_id}" body = """
There should be an image here: