We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Signature Images being counted as an attachment(C#)

Hi Support Team,

We have an in-house application that checks the mails in the mailbox and sees if we failed to ingest any mails or attachments. So recently, I have run into an issue where while comparing the attachments that we ingested successfully, the count from Aspose showing higher as it is also counting the image of the company’s logo that some people attach in their mail

I supposed this is due to the fact that it also counts the images in the body as attachment. I have attached pieces of the code I am using below, can you please tell me how I can get the count of only actually attached attachments and exclude the inline attachments while iterating through the list of attachments in the line:

foreach (ExchangeAttachmentInfo attachment in attachmentInfo)

This is the sample code explaining what I am trying to do:

ExchangeFolderInfo subfolderInfo = new ExchangeFolderInfo();
ExchangeQueryBuilder builder = new ExchangeQueryBuilder();
builder.InternalDate.Since(from, DateComparisonType.ByDateTime);
builder.InternalDate.BeforeOrEqual(to, DateComparisonType.ByDateTime);
MailQuery query = builder.GetQuery();
ExchangeMessageInfoCollection messages = client.ListMessages(mailboxInfo.InboxUri, query);
if (messages.Count > 0)
{
	//For each email in the mailbox
	foreach (ExchangeMessageInfo msgInfo in messages)
	{
		if (!(msgInfo.Subject == null))
		{
			//Creating new Mail template to store mail info
			EmailObjectModel emailMailBox = new emailMailBox();
			//MessageInfo is of the type ExchangeMessageInfo
			emailMailBox.MessageInfo = msgInfo;

			ExchangeAttachmentInfoCollection attachmentInfo = new ExchangeAttachmentInfoCollection();

			//Get attachments from the source mailbox mail
			attachmentInfo = emailMailBox.MessageInfo.Attachments;

			//If there is a mismatch in ingested attachment count from mailbox mail attachment count
			if (attachmentInfo.Count != IngestedAttachments.Count)
			{
				foreach (ExchangeAttachmentInfo attachment in attachmentInfo)
				{
					//Below code checks if the attachment has been ingested in DB
					var attchmnt = from parent in attachmentList
								   where parent.Doctitle == attachment.Name
								   && parent.IsParent == 0
								   select parent;
								   
					//If the attachment was not ingested, get attachment and put it in ICC path
					if (attchmnt.Count() == 0 || attchmnt == null)
					{
						//Extracting the missing Attachment and placing in ICC source path
						Attachment att = emailMailBox.client.FetchAttachment(attachment.AttachmentUri);
						att.Save(@ICCPath + attachment.Name);
					}
				}
			}
		}
	}
}

@sin2akshay,

Can you please share source file along with working sample cde so that we may further investigate to help you out. The sample code that has been shared does not seem complete.

SignatureTest001_041919.zip (18.0 KB)
Hi, I have already provided the sample code and explained it. PFA a sample mail which has a signature image as well as an image in the body. But the actual attachment in the mail is just 1.

ExchangeAttachmentInfoCollection attachmentInfo = new ExchangeAttachmentInfoCollection();

//Get attachments from the source mailbox mail
attachmentInfo = emailMailBox.MessageInfo.Attachments;

//The count is coming 3 rather it should be 1
Console.WriteLine(attachmentInfo.Count);

@sin2akshay,

I have worked with source file shared by you using Aspose.Email 19.3 and unable to observe email attachment issue. Can you please share which Aspose.Email version you are using on your end so that we may further investigate to help you out.

Hi @Adnan.Ahmad,

Can you explain what do you mean by being unable to observe the email attachment issue? Did you get the count as 1, if so please share the code you used?

Also, sorry for being a noob, but the aspose was already included in the application code (dll file) when it was handed over to me for enhancement. Can you tell me where can I check the version or is it possible to check it through code?

@sin2akshay,

I have shared sample code with you. Please check. Also you can check your version in reference properties of the project. Please share feedback with us.

string path = “F:\Aspose Work\”;

  	MailMessage eml = MailMessage.Load(path+ "SignatureTest001_041919.msg");

  		Console.WriteLine(eml.Attachments.Count);
  	Console.ReadKey();