Using Graph API retrieve digitally signed PDF from email attachment in C#

Chandra Singh, Krishna 0 Reputation points
2025-04-09T09:16:45.9433333+00:00

Hi All,

Any one can suggest that how to retrieve digitally signed PDF document from email attachment using Graph API in C#.

We have so many such email which needs to read the content from digitally signed PDF document.

When I am trying to retrieve digitally signed pdf from email attachment, I am getting only "smime.p7m"

Here is my Code

OutlookItem outlookItem = null;

var result = (ItemAttachment)_appClient.Users[_appSettings.MailBox].Messages[message.Id].Attachments[attachment.Id]

.GetAsync((requestConfiguration) =>

{

	requestConfiguration.QueryParameters.Expand = new string[] { "microsoft.graph.itemattachment/item" };

}).Result;

outlookItem = result.Item;

if (outlookItem != null && outlookItem is Message)

{

	Message messageItem = outlookItem as Message;

	if (messageItem != null && messageItem.Attachments.Count > 0)

	{

		foreach (var attachment1 in messageItem.Attachments)

		{

			if (attachment1 is FileAttachment)

			{

				var fileAttachment = (FileAttachment)attachment1;

				string file_extension = Path.GetExtension(fileAttachment.Name);

				if (file_extension == "" || file_extension.ToLower() == ".png" || file_extension.ToLower() == ".jpg" || file_extension.ToLower() == ".jpeg")

				{

					continue;

				}

				string fileName = string.Empty;

				fileName = GenerateFileName(attachment1.Name);

				var filePath = string.Concat(AttachmentPath, fileName);

				fileAttachment.Save(filePath); // I am not getting actaul attachement.

			}

		}

	}

}

Thank you in advance

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,482 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.