Append an e-mail to 'sent' using Microsoft Graph?

184 views Asked by At

I use PHPMailer to send e-mails from an application. For IMAP-bases accounts, I can then imap_append the e-mail I just sent to the .Sent folder, so that to the user, it is like he or she sent the e-mail. I would like to do the same with Microsoft Graph, so send the e-mail through PHPMailer, and then append the message to the sent folder in the Office365/Microsoft365 e-mail account. Is that possible? When I look at the docs, it seems to lean to either creating a draft message, or sending the whole thing through the API.

1

There are 1 answers

1
Glen Scales On

If you set the extended property for pidTagMessageFlags https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtagmessageflags-canonical-property to 4 when you create the Message (eg create a draft or Post to the SentItems folder) that will create a Message that looks like it was sent.

eg

POST https://graph.microsoft.com/v1.0/me/mailfolders/sentitems/messages

{
    "subject": "Meet for lunch?",
    "body": {
        "contentType": "Text",
        "content": "The new cafeteria is open."
    },
    "toRecipients": [
        {
            "emailAddress": {
                "address": "[email protected]"
            }
        }
    ],
    "singleValueExtendedProperties": [
        {
            "id": "Integer 0x0E07",
            "value": "4"
        }
    ]
}