Skip to content
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

Issue with Office 365 Payload Construction in NotifyOffice365 #1271

Closed
Kathir18K opened this issue Jan 17, 2025 · 1 comment · Fixed by #1274
Closed

Issue with Office 365 Payload Construction in NotifyOffice365 #1271

Kathir18K opened this issue Jan 17, 2025 · 1 comment · Fixed by #1274
Labels

Comments

@Kathir18K
Copy link

Description

When sending emails through the Office 365 notifier, the subject and body are not being included in the final payload, resulting in empty emails. This appears to be due to how the payload dictionary is being updated in the send() method of the NotifyOffice365 class.


Current Behavior

  • Emails are sent successfully (202 response).
  • The payload only includes from, toRecipients, and saveToSentItems.
  • Subject and body are missing from the final payload.
  • The issue occurs with both notify() and send() methods.

Expected Behavior

  • The subject and body should be included in the final payload sent to the Microsoft Graph API.
  • Emails should contain the specified subject and body content.

Debug Log Evidence

# Current Payload (from debug logs):
{
    "message": {
        "from": {
            "emailAddress": {
                "address": "user@domain.com",
                "name": "Apprise"
            }
        },
        "toRecipients": [{
            "emailAddress": {
                "address": "user@domain.com"
            }
        }]
    },
    "saveToSentItems": "true"
}

# Expected Payload:
{
    "message": {
        "subject": "Test Email",
        "body": {
            "contentType": "Text",
            "content": "This is a test email body"
        },
        "from": {
            "emailAddress": {
                "address": "user@domain.com",
                "name": "Apprise"
            }
        },
        "toRecipients": [{
            "emailAddress": {
                "address": "user@domain.com"
            }
        }]
    },
    "saveToSentItems": "true"
}

Root Cause

The issue occurs in the NotifyOffice365.send() method of the Office 365 plugin. The payload dictionary is being overwritten instead of merged when adding the 'from' information, causing loss of subject and body data.

Current Implementation:

def send(self, body, title='', notify_type=NotifyType.INFO, attach=None, **kwargs):
   """
   Perform Office 365 Notification
   """
   # ... rest of the implementation remains the same
   payload = {
       'message': {
           'subject': title,
           'body': {
               'contentType': content_type,
               'content': body,
           },
       },
       'saveToSentItems': 'true'
   }

   # This update overwrites the entire 'message' dictionary
   payload.update({
       'message': {
           'from': {
               "emailAddress": {
                   "address": self.from_email,
                   "name": self.from_name or self.app_id,
               }
           },
       }
   })
    # ... rest of the implementation remains the same

Suggested Fix

The issue can be resolved by properly merging the dictionaries instead of overwriting them. Here's the proposed fix for the send() method in NotifyOffice365:

def send(self, body, title='', notify_type=NotifyType.INFO, attach=None, **kwargs):
   """
   Perform Office 365 Notification
   """
    # ... rest of the implementation remains the same
   payload = {
       'message': {
           'subject': title,
           'body': {
               'contentType': content_type,
               'content': body,
           },
       },
       'saveToSentItems': 'true'
   }

    # ... rest of the implementation remains the same
   payload['message'].update({
       'from': {
           "emailAddress": {
               "address": self.from_email,
               "name": self.from_name or self.app_id,
           }
       }
   })
    # ... rest of the implementation remains the same
   payload['message'].update({
       'toRecipients': [{
           'emailAddress': {
               'address': self.source
           }
       }]
   })

    # ... rest of the implementation remains the same
@Kathir18K Kathir18K added the bug label Jan 17, 2025
@caronc caronc linked a pull request Jan 19, 2025 that will close this issue
4 tasks
@caronc
Copy link
Owner

caronc commented Jan 19, 2025

Well that's embarassing 👀 . Great find and thank you so much for pin-pointing the solution.

I additionally added some unit tests to prevent this from ever happening again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants