pyOutlook.core package

Submodules

pyOutlook.core.folders module

class pyOutlook.core.folders.Folder(folder_id, folder_name, parent_id, child_folder_count, unread_count, total_items)

Bases: object

An object representing a Folder in the OutlookAccount provided.

folder_id

The static id generated by Outlook to identify this folder.

folder_name

The name of this folder as displayed in the account

parent_id

The id of the folder which houses this Folder object

child_folder_count

The number of child folders inside this Folder

unread_count

The number of unread messages inside this Folder

total_items

A sum of all items inside Folder

copy_folder(destination_folder)

Copies the Folder into the provided destination folder.

Raises:

AuthError – Raised if Outlook returns a 401, generally caused by an invalid or expired access token.

Parameters:
  • destination_folder – A string containing the id of the folder, as provided by Outlook, that this Folder
  • be copied to. (should) –
Returns:

A new Folder representing the newly created folder.

create_child_folder(folder_name)

Creates a child folder within the Folder it is called from and returns the new Folder object.

Parameters:folder_name – The name of the folder to create

Returns: Folder

delete_folder()

Deletes this Folder.

Warning

This deletes the folder inside of the account provided - not the Folder object!

Raises:AuthError – Raised if Outlook returns a 401, generally caused by an invalid or expired access token.
get_subfolders()

Retrieve all child Folders inside of this Folder.

Raises:AuthError – Raised if Outlook returns a 401, generally caused by an invalid or expired access token.
Returns:List[Folder]
move_folder(destination_folder)

Move the Folder into a different folder.

This makes the Folder provided a child folder of the destination_folder.

Raises:AuthError – Raised if Outlook returns a 401, generally caused by an invalid or expired access token.
Parameters:destination_folder – An id, provided by Outlook, specifying the folder that should become the parent
Returns:A new Folder object representing the folder that is now inside of the destination_folder.
rename_folder(new_folder_name)

Renames the Folder to the provided name.

Parameters:new_folder_name – A string of the replacement name.
Raises:AuthError – Raised if Outlook returns a 401, generally caused by an invalid or expired access token.
Returns:A new Folder representing the folder with the new name on Outlook.
pyOutlook.core.folders.clean_return_multiple(json)
pyOutlook.core.folders.get_folder(self, folder_id)
pyOutlook.core.folders.get_folders(self)

pyOutlook.core.main module

class pyOutlook.core.main.OutlookAccount(access_token)

Bases: object

Sets up access to Outlook account for all methods & classes.

Access token required for instantiation. Can be refreshed at a later time using .set_access_token().

Warning

This module does not handle the OAuth process. You must retrieve and refresh tokens separately.

access_token

A string OAuth token from Outlook allowing access to a user’s account

deleted_messages()

Retrieves last ten deleted messages.

Returns:list[Message]
draft_messages()

Retrieves last ten draft messages.

Returns:list[Message]
get_deleted_messages()

Retrieves last ten deleted messages.

Returns:list[Message]

Warning

This method is deprecated, use deleted_messages() instead

get_draft_messages()

Retrieves last ten draft messages.

Returns:list[Message]

Warning

This method is deprecated, use draft_messages() instead

get_folder(folder_id)

Retrieve a Folder object matching the folder ID provided.

Parameters:folder_id – String identifying the Outlook folder to return
Returns:Folder
get_folder_messages(folder)

Retrieve first ten messages from provided folder.

Parameters:folder – String providing the folder ID, from Outlook, to retrieve messages from
Returns:list[Message]
get_folders()

Retrieves a list of folders in the account.

Returns:list[Folder]
get_inbox()

Retrieves first ten messages in account’s inbox.

Returns:List[Message]

Warning

This method is deprecated, use inbox() instead

get_message(message_id) → pyOutlook.core.message.Message

Gets message matching provided id.

Retrieves the Outlook email matching the provided message_id.

Parameters:message_id – A string for the intended message, provided by Outlook
Returns:Message
get_messages()

Get first 10 messages in account, across all folders.

Returns:List[Message]
get_more_messages(page)

Retrieves additional messages, across all folders, indicated by ‘page’ number. get_messages() fetches page 1.

Parameters:page (int) – Integer representing the ‘page’ of results to fetch
Returns:List[Message]
get_sent_messages()

Retrieves last ten sent messages.

Returns:list[Message]

Warning

This method is deprecated, use sent_messages() instead

inbox()

Retrieves first ten messages in account’s inbox.

Returns:List[Message]
new_email()

Creates a NewMessage object.

Returns:NewMessage
send_email(body=None, subject=None, to=None, cc=None, bcc=None, send_as=None, attachment=None)

Sends an email in one method using variables to set the various pieces of the email.

Parameters:
  • body (str) – The body of the email
  • subject (str) – The subject of the email
  • to (list) – A list of email addresses
  • cc (list) – A list of email addresses which will be added to the ‘Carbon Copy’ line
  • bcc (list) – A list of email addresses while be blindly added to the email
  • send_as (str) – A string email address which the OutlookAccount has access to
  • attachment (dict) – A dictionary with three parts [1] ‘name’ - a string which will become the file’s name [2] ‘ext’ - a string which will become the file extension [3] ‘bytes’ - the bytes of the file.
sent_messages()

Retrieves last ten sent messages.

Returns:list[Message]
set_access_token(access_token)

Sets access token.

Set the access token after creating an OutlookAccount object.

Parameters:access_token – A string representing the OAuth token
Returns:None
token

pyOutlook.core.message module

class pyOutlook.core.message.Message(message_id: str, body: str, subject: str, sender_email: str, sender_name: str, to_recipients: list)

Bases: object

An object representing an email inside of the OutlookAccount.

message_id

A string provided by Outlook identifying this specific email

body

The body content of the email, including HTML formatting

subject

The subject of the email

senderEmail

The email of the person who sent this email

senderName

The name of the person who sent this email, as provided by Outlook

toRecipients

A comma separated string of emails who were sent this email in the ‘To’ field

copy_to(folder_id)

Copies the email to the folder specified by the folder_id.

The folder id must match the id provided by Outlook.

Parameters:folder_id – A string containing the folder ID the message should be copied to
copy_to_deleted()

Copies Message to account’s Deleted Items folder

copy_to_drafts()

Copies Message to account’s Drafts folder

copy_to_inbox()

Copies Message to account’s Inbox

delete_message()

Deletes the email

forward_message(to_recipients, forward_comment)

Forward Message to recipients with an optional comment.

Parameters:
  • to_recipients – Comma separated string list of recipients to send email to.
  • forward_comment – String comment to append to forwarded email.

Examples

>>> email.forward_message('john.doe@domain.com, betsy.donalds@domain.com')
>>> email.forward_message('john.doe@domain.com', 'Hey Joe')
Raises:
  • MiscError – A comma separated string of emails, or one string email, must be provided
  • AuthError – Raised if Outlook returns a 401, generally caused by an invalid or expired access token.
move_to(folder_id)

Moves the email to the folder specified by the folder_id.

The folder id must match the id provided by Outlook.

Parameters:folder_id – A string containing the folder ID the message should be moved to
move_to_deleted()

Moves the email to the account’s Deleted Items folder

move_to_drafts()

Moves the email to the account’s Drafts folder

move_to_inbox()

Moves the email to the account’s Inbox

reply(reply_comment)

Reply to the Message.

Notes

HTML can be inserted in the string and will be interpreted properly by Outlook.

Parameters:reply_comment – String message to send with email.
reply_all(reply_comment)

Replies to everyone on the email, including those on the CC line.

With great power, comes great responsibility.

Parameters:reply_comment – The string comment to send to everyone on the email.

Module contents