Skip to content

Add email receipt notifications through webhooks #1137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions O365/mailbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ class Folder(ApiComponent):
"copy_folder": "/mailFolders/{id}/copy",
"move_folder": "/mailFolders/{id}/move",
"message": "/messages/{id}",
"subscriptions": "/subscriptions",
}
message_constructor = Message

Expand Down Expand Up @@ -1045,3 +1046,61 @@ def get_settings(self):
parent=self, **{self._cloud_data_key: data}
)

'''
def set_email_subscription(self, notificationurl, minutes):
"""Set a webhook subscription to send post request every
time an email is received

:return: response from the connection
:rtype: connection
"""

# Get the current UTC time
now_utc = dr.datetime.utcnow()

# Calculate the future time by adding 4200 minutes
future_utc = now_utc + dt.timedelta(minutes=minutes)

# Format with 7 decimal places and append 'Z' to indicate UTC
# '%f' gives 6 digits for microseconds; we add an extra '0' for 7 decimal places.
expiration_str = future_utc.strftime("%Y-%m-%dT%H:%M:%S.%f0Z")

url = "https://graph.microsoft.com/v1.0/subscriptions"

params = {
"changeType": "created,updated",
"notificationUrl": notificationurl,
"resource": "/me/mailfolders('inbox')/messages",
"expirationDateTime": expiration_str,
}

response = self.con.get(url, params=my_params)


def renew_email_subscription(self, id, minutes):
"""Renew a webhook subscription to send post request every
time an email is received

:return: response from the connection
:rtype: connection
"""

# Get the current UTC time
now_utc = dr.datetime.utcnow()

# Calculate the future time by adding 4200 minutes
future_utc = now_utc + dt.timedelta(minutes=minutes)

# Format with 7 decimal places and append 'Z' to indicate UTC
# '%f' gives 6 digits for microseconds; we add an extra '0' for 7 decimal places.
expiration_str = future_utc.strftime("%Y-%m-%dT%H:%M:%S.%f0Z")

url = f'https://graph.microsoft.com/v1.0/subscriptions/{id}'

params = {
"expirationDateTime": expiration_str,
}

response = self.con.get(url, params=my_params)

'''