EWS: Mailbox address from a Calendar FolderId, is it possible? - c#

I have stored Calendar FolderIds in order report on calendar events which a user has access to. I'm using Exchange Web Services via c# (using Microsoft.Exchange.WebServices)
These calendars can be associated with the authenticated user's mailbox, a shared mailbox, an impersonated|delegated mailbox, or a public mailbox. And now I'd like to go from the FolderId to the mailbox address.
Ideally there'd be a function to
string address = getMailboxAddress(new FolderId("AAJk...AA="));

If you have the FolderId what you have is the EWS version of this https://msdn.microsoft.com/en-us/library/ee217297(v=exchg.80).aspx which means with the data you have doesn't contain the Email Address. You would be better at the time you store the CalendarId store the Email address its associated with.
You can try using ConvertId with a generic non resolvable email Address this should return the EmailAddress the folder belongs (won't work for Public Folder) to eg
AlternateId aiAlternateid = new AlternateId(IdFormat.EwsId, SharedFoder.Id.UniqueId, "mailbox#domain.com");
AlternateIdBase aiResponse = service.ConvertId(aiAlternateid, IdFormat.EwsId);
Console.WriteLine(((AlternateId)aiResponse).Mailbox);
Cheers
Glen

Related

VSTO - How get account email address from Outlook.Store entity

Some time ago to get Outlook accounts and account info (e.g. Email address, SMTP address) i was use Outlook.Accounts entity, but Outlook.Accounts caches data and doesn't support events like Add/Remove. Here I was offered to switch to Outlook.Stores (Outlook.Store) entity, but I don’t understand how I can get the Email address from Outlook.Store at least.
If the store is associated with any account configured in Outlook you can use the following code which iterates over all accounts configured and finds the required one where you may ask for an email address:
Outlook.Account GetAccountForFolder(Outlook.Folder folder)
{
// Obtain the store on which the folder resides.
Outlook.Store store = folder.Store;
// Enumerate the accounts defined for the session.
foreach (Outlook.Account account in Application.Session.Accounts)
{
// Match the DefaultStore.StoreID of the account
// with the Store.StoreID for the currect folder.
if (account.DeliveryStore.StoreID == store.StoreID)
{
// Return the account whose default delivery store
// matches the store of the given folder.
return account;
}
}
// No account matches, so return null.
return null;
}
The Account.SmtpAddress property returns a string representing the Simple Mail Transfer Protocol (SMTP) address for the Account. The purpose of SmtpAddress and Account.UserName is to provide an account-based context to determine identity. If the account does not have an SMTP address, SmtpAddress returns an empty string.
Generally, stores do not have an intrinsic identity - imagine a standalone PST store: there is no user identity associated with it. Or you can have multiple POP3/SMTP accounts delivering to the same PST store - you now have multiple identities associated with the PST store.
Or imagine having a PF store - it is accessible to multiple users without having its own identity.
Only Exchange stores have a notion of an owner. You can go from an Exchange store to an email account by looping through the Namespace.Accounts collection and comparing (using Namespace.CompareEntryIDs) the entry id of your store in question and the store exposed by the Account.DeliveryStore property.
If using Redemption is an option (I am its author), it exposes the Exchange mailbox owner directly through the RDOExchangeMailboxStore.Owner property (returns RDOAddressEntry object).

Find User mailbox GUID using their email address EWS

I am working on Outlook add-in and doing some Encryption and Decryption. I created some hashed string on the server during POST request. That string is later passed to GET request and on the server I need to compare that hashed string to see if the user is the same user who did POST request.
When I make a GET request I also send user smtp using Office.context.mailbox.userProfile.emailAddress.
Question: How can find user mailboxGUID(or account information which will include mailboxGUID and more) using their email address?
Do you want the AD/Directory GUID or the ExchangeGUID ? you can get the ADGuid using ResolveName and specifying the property set (this works from 2010 up) eg
PropertySet exProp = new PropertySet(BasePropertySet.FirstClassProperties);
NameResolutionCollection ncCol = service.ResolveName("user#domain.com", ResolveNameSearchLocation.DirectoryOnly, true, exProp);
if (ncCol.Count == 1)
{
Console.WriteLine(ncCol[0].Contact.DirectoryId);
}
The MailboxGUID makes up part of the FolderId format so can be parsed out that https://msdn.microsoft.com/en-us/library/ee217297(v=exchg.80).aspx if you really need it.

Register and use User's email domain

In my current application i want to add a new feature that customers will be able to register their own email domain server if they have any. Currently i am sending all emails using my own application domain.
I want to know how we can accomplish that using ASP.NET WebApi & C# that user will allow to validate and register their own email domains instead of using the default one.
Do we need user's DKIM and SPF records ?
If the user provides the credentials to their own email service
Then you don't need to look at DKIM and SPF records. The user should do that himself.
You will have to collect from the user:
email service type (smtp, mandrill, postmarkapp...)
email service host name (if smtp)
credentials or api key
and maybe service-specific options
If you use your own service to send emails
Then the user will have to add a DKIM entry and update the SPF entry on their domain name. You will have to provide the values to your user depending on your email service.
You can take inspiration from all those services that allow the same kind of feature (mailchimp, mandrill, postmarkapp, zoho...).
Check for DNS email records
In both cases, you can use a DNS client to verify the DNS records are OK. You will be able to tell the user whether records are missing.
Here a sample code to start checking the SPF record with ARSoft.Tools.Net.
var client = new DnsClient(servers, 10000);
var spfRecords = client.Resolve(item.Name, RecordType.Txt);
if (result.AnswerRecords == null || result.AnswerRecords.Count == 0 || result.ReturnCode == ReturnCode.NxDomain)
{
// spf record is missing
}
else if (result.AnswerRecords.Count == 1)
{
// check the record value with SpfRecord.TryParse(item.ActualValue, out spf)
}
else
{
// too many spf records
}

MS Exchange server cloud, getting all items in a different

I am trying to figure out how to access all items from a 'room' account.
Is it possible to somehow access the data from the room when that user isn't a real user?
I can get all rooms but the question is how to query the finditems using the room account.
You will need to authenticate as some user with a Mailbox and then grant that user access to the Room's Calendar (or the whole mailbox using Add-MailboxPermissions) or make it a delegate. Then you can just use the FolderId overload to specify you want to query that Room's Calendar folder eg
FolderId RoomMailboxCalendarFolderId = new FolderId(WellKnownFolderName.Calendar, "room#domain.com");
CalendarView cvCalView = new CalendarView(DateTime.Now, DateTime.Now.AddDays(31));
FindItemsResults<Appointment> appointments = service.FindAppointments(RoomMailboxCalendarFolderId, cvCalView);
Cheers
Glen

Office 365 Exchange Mailbox Properties

I would like to know how to access a set of given mailboxes and get various properties on those mailboxes. Specifically I would like to iterate through a list of email addresses, and spit out the type of mailbox (ie: room mailbox, user mailbox , etc.)and who and what type of access users have. I've been looking at url below, but cant find much on this type of thing.
https://code.msdn.microsoft.com/Office365/
An code samples would be greatly appreciated.
Pseudo Code:
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013);
var MyMailboxes = service.getMailboxes(MyListofMailboxes);
foreach(var mailbox in MyMailboxes)
{
Console.WriteLine("MailboxType: {0}" + mailbox.MailboxType);
foreach(var userAccess in mailbox.UserAccess)
{
Console.Writeline("User: {0}, Access Level: {1}", userAccess.user, userAccess.AccessLevel);
}
}
You need to use Remote Powershell to do that see https://msdn.microsoft.com/en-us/library/office/ff326159(v=exchg.150).aspx. You can the use Get-Mailbox, Get-MailboxPermission and Get-MailboxFolderPermissions . EWS is only useful if you want to access the Mailbox content for Admin tasks you should use Remote Powershell.
Cheers
Glen

Categories