I have got email object and also attachment by using
Mail.attachments.count but archived email is not working because it is using enterprise vault.
I am getting attachments but archived email is not working and giving 0 or 1 count
I have gone through the body of the emails and found that when an email is archived, the attachments are shown either in two ways as below.
1st
<<Attachments data>>
2nd
Attachments:
Attachments data
In order to get the attachments, the below logic can be used:
if(strEmailBody!=null && strEmailBody.LastIndexOf("<<") != -1 && strEmailBody.LastIndexOf(">>") != -1)
{
iStartIndex = strEmailBody.LastIndexOf("<<") + 2;
iLastIndex = strEmailBody.LastIndexOf(">>") - 2;
string strAttachmentsData = strEmailBody.Substring(iStartIndex, iLastIndex - iStartIndex);
var regexObj = new Regex(@".*\)");
var allMatchResults = regexObj.Matches(strAttachmentsData);
}
else if(strEmailBody != null && strEmailBody.LastIndexOf("Attachments:")!=-1)
{
iStartIndex = strEmailBody.LastIndexOf("Attachments:") + 12;
string strAttachmentsData = strEmailBody.Substring(iStartIndex, strEmailBody.Length - iStartIndex-1);
MatchCollection allMatchResults = null;
var regexObj = new Regex(@".*\)");
allMatchResults = regexObj.Matches(strAttachmentsData);
}