EWS Managed - Is it possible to get full "From" details using "FindItems"? - exchangewebservices

I'm using the Exchange Web Services Managed API to search a message folder using FindItems. The code I'm using is this:
var search = new SearchFilter.ContainsSubstring(
ItemSchema.Subject,
"subject I want");
ItemView searchView = new ItemView(9999);
searchView.PropertySet = new PropertySet(
BasePropertySet.IdOnly,
ItemSchema.Subject,
ItemSchema.DateTimeReceived,
EmailMessageSchema.From);
searchView.OrderBy.Add(
ItemSchema.DateTimeReceived,
SortDirection.Descending);
searchView.Traversal = ItemTraversal.Shallow;
var searchResults = _service.FindItems(
folderToSearch.Id,
search,
searchView);
The search works fine, and the properties I've specified in the searchView.PropertySet do get returned. The problem is that it doesn't return all of the details of From.
I iterate searchResults, and cast the items to type EmailMessage or PostItem as appropriate, to access the From property, which returns an EmailAddress object. On that object, the Name property is set, but Address is null.
If I then bind the item, like:
var boundItem = Item.Bind(_service, message.Id);
var boundItemEmail = boundItem as EmailMessage;
Then boundItemEmail.From.Address is not null, it returns the senders email address.
The trouble is, binding a message can be a rather time-consuming process, compared to the much faster FindItems operation.

You should be able to use the LoadPropertiesForItems method to get the From property, it's faster than binding to individual messages.

Related

Get email message from Exchange using EWS Tracking Log Message ID or the InternalMessageID

I'm developing an application that tracks exchange email messages in our company.
We where able to get info out from the tracking log, but in the log -by design- there is no subject or body message.
So the next step for us was using EWS to get the message detail when needed.
The question is that in the tracking log we find to IDs :
MessageId in format "F533E7F015A2E24F8D8ABFE2587117C601EDF245#blstex02.subdomain.domain.com"
and
InternalMessageId in format "5840818"
If in EWS we use this id to find the message by id we always get an "Id is malformed." exception.
Here is the code we use:
public static EmailMessage GetEmailById(string uNameToImpersonate, string StringItemId)
{
return EmailMessage.Bind(GetService(uNameToImpersonate), new ItemId(StringItemId));
}
I'm a newbie to EWS so maybe I'm missing something really easy...
Thanks for your help
You can only bind to a Message using the EWSId see https://msdn.microsoft.com/en-us/library/office/dn605828(v=exchg.150).aspx for a more detailed discussion.For the InternetId you will need to search for messages with that particular Id using the findItem operation eg something like
ItemView ivew = new ItemView(1);
service.TraceEnabled = true;
ExtendedPropertyDefinition PidTagInternetMessageId = new ExtendedPropertyDefinition(4149, MapiPropertyType.String);
SearchFilter sf = new SearchFilter.IsEqualTo(PidTagInternetMessageId, "F533E7F015A2E24F8D8ABFE2587117C601EDF245#blstex02.subdomain.domain.com");
FindItemsResults<Item> iCol = service.FindItems(WellKnownFolderName.Inbox, sf, ivew);
foreach (Item item in iCol.Items)
{
Console.WriteLine(item.Subject);
}

Independentsoft Exchange Web Services HTML from message is null

Using the code examples provided by Independentsoft:
PropertyName myPropertyName = new PropertyName("Disabled", StandardPropertySet.PublicStrings, MapiPropertyType.String);
Exists restrictionExists = new Exists(myPropertyName);
response = service.FindItem(StandardFolder.Inbox, MessagePropertyPath.AllPropertyPaths, new Not(restrictionExists));
we are getting the message but the BodyHtmlText is null...
Using Exchange Server 2010 SP2.
Anyone had any problems with this?
FindItems doesn't return the body (and a number of other properties) you need to make a GetItem Request on the Item in question to get these properties see https://msdn.microsoft.com/en-us/library/bb508824.aspx

how to keep all created IDs in Postman Environment

I am trying to automate API requests using postman. So first in POST request I wrote a test to store all created IDs in Environment : Which is passing correct.
var jsondata = JSON.parse(responseBody);
tests["Status code is 201"] = responseCode.code === 201;
postman.setEnvironmentVariable("BrandID", jsondata.brand_id);
Then in Delete request I call my Environment in my url like /{{BrandID}} but it is deleting only the last record. So my guess is that environment is keeping only the last ID? What must I do to keep all IDs?
Each time you call your POST request, you overwrite your environment variable
So you can only delete the last one.
In order to process multiple ids, you shall build an array by adding new id at each call
You may proceed as follows in your POST request
my_array = postman.getEnvironmentVariable("BrandID");
if (my_array === undefined) // first time
{
postman.setEnvironmentVariable("BrandID", jsondata.brand_id); // creates your env var with first brand id
}
else
{
postman.setEnvironmentVariable("BrandID", array + "," + jsondata.brand_id); // updates your env var with next brand id
}
You should end up having an environment variable like BrandId = "brand_id1, brand_id2, etc..."
Then when you delete it, you delete the complete array (but that depends on your delete API)
I guess there may be cleaner ways to do so, but I'm not an expert in Postman nor Javascript, though that should work (at least for the environment variable creation).
Alexandre

Username in WebTokenRequestResult is empty

in a Windows 10 UWP I try use WebAuthenticationCoreManager.RequestTokenAsync to get the result from a login with a Microsoft account.
I get a WebTokenRequestResult with Success. ResponseData[0] contains a WebAccount with an ID - but the UserName is empty.
The scope of the call is wl.basic - so I should get a lot of information...
I'm not sure how to retrieve extra information - and for the current test the Username would be OK.
I checked out the universal samples - and there I found a snippet which tries to do what I'm trying - an output of webTokenRequestResult.ResponseData[0].WebAccount.UserName.
By the way - the example output is also empty.
Is this a bug - or what do I (and the MS in the samples) have to do to get the users profile data (or at least the Username)?
According to the documentation (https://learn.microsoft.com/en-us/windows/uwp/security/web-account-manager), you have to make a specific REST API call to retrieve it:
var restApi = new Uri(#"https://apis.live.net/v5.0/me?access_token=" + result.ResponseData[0].Token);
using (var client = new HttpClient())
{
var infoResult = await client.GetAsync(restApi);
string content = await infoResult.Content.ReadAsStringAsync();
var jsonObject = JsonObject.Parse(content);
string id = jsonObject["id"].GetString();
string name = jsonObject["name"].GetString();
}
As to why the WebAccount property doesn't get set... shrugs
And FYI, the "id" returned here is entirely different from the WebAccount.Id property returned with the authentication request.

How to get the ItemId of a forwarded email in ExchangeWebServices Managed API

I am using the EWS Managed API to find an EmailItem and forward it to another recipient. I want to record the ItemId of the forwarded email, but I can't figure out how to find this property.
var originalMail = EmailMessage.Bind(exchangeService, originalMailId);
var fwdMessage = originalMail.CreateForward();
fwdMessage.ToRecipients.Add("foo#bar.com");
fwdMessage.BodyPrefix = new MessageBody(BodyType.HTML, html);
fwdMessage.Subject = "Testing 123";
// Send the message
fwdMessage.SendAndSaveCopy();
How can I get the ItemId of the fwdMessage email?
It seems that the ResponseMessage object doesn't expose an ID. You could try stamping a GUID in a custom extended property before sending, then searching Sent Items for the item that has that GUID.