0

I need to get the default email (which is selected in File > Account Settings > Account Settings).

I have tried to get it in different ways:

var outlookApp = new Application();
var defaultEmail = OutlookApp.Session.DefaultStore.DisplayName;

var outlookNamespace = outlookApp.GetNamespace("MAPI");
defaultEmail = outlookNamespace.GetDefaultFolder(OlDefaultFolders.olFolderInbox).Store.DisplayName;

defaultEmail = outlookNamespace.DefaultStore.DisplayName;

But all ways return the email of my Exchange account, not the default email I chose (e.g. myExample@gmail.com). Is there any way to get the default email?

Austin
  • 2,203
  • 3
  • 12
  • 28
Alldman
  • 15
  • 7
  • Got the default email this way: ``OutlookApp.Session.Accounts.FirstOrDefault()?.DisplayName``. But I'm not sure if this is the optimal way to do it – Alldman Aug 21 '23 at 14:48

1 Answers1

0

Use Application.Session.CurrentUser.AddressEntry.

From there, you can either use AddressEntry.Address or, in case of an Exchange account, AddressEntry.GetExchangeUser().PrimarySmtpAddress

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Unfortunately, both suggested ways only return the email of my Exchange mail, not the one I added via smtp/imap and assigned by default. Only ``outlookApp.Session.Accounts.FirstOrDefault()?.DisplayName`` works correctly. But I don't like this way. It doesn't work if you reassign the default email and don't restart Outlook – Alldman Aug 21 '23 at 16:00
  • If you prefer to work with the accounts, use `Account.SmtpAddress` property rather than `Account.DisplayName` – Dmitry Streblechenko Aug 21 '23 at 16:19