I'm trying to integrate outlook with an emailing solution that we are creating. I initially integrated Gmail for sending the attachments, I stored the uploaded file in a cloud storage bucket and sent the attachment as an URL in gmail.
The Gmail API allows us to send attachments as such:
attachments = attachments.map((file) => ({
filename: file.original_name,
path: file.attachment_url
}));
Essentially, filename and path (as the url) seem to suffice when we try to send the email with an attachment.
For the Outlook Integration, we were trying the referenceAttachment resource type as specified in :
https://learn.microsoft.com/en-us/graph/api/resources/referenceattachment?view=graph-rest-beta
It didn't seem to work.
It is a requirement for me to send my attachments as a url because that is how I'm storing it. We have automated mailing services as well and we store the attachment urls with the templates for the same.
Here's a code snippet of how we were creating our attachment list:
attachments: attachments.map((file) => {
let fileExtension = file.original_name?.split('.')?.pop();
let contentType = MIME_TYPES[fileExtension];
if (!contentType) return {};
return {
'@odata.type': '#microsoft.graph.referenceAttachment',
name: file.original_name,
sourceUrl: file.attachment_url,
contentType: contentType
}
}
),
},
Although the attachments are being sent, they are being downloaded as raw files without a MIME TYPE or format.Here's what happened