HostApplication inside ADXOlForm to get outlook accounts

Add-in Express™ Support Service
That's what is more important than anything else

Only registered users are allowed to subscribe.
HostApplication inside ADXOlForm to get outlook accounts
 
Subscribe
wxnko




Posts: 2
Joined: 2020-09-22
I started with this in outlook.
https://www.add-in-express.com/creating-addins-blog/2014/11/26/access-outlook-html-javascript-addins/

I changed form to rightdock. Now I want to use this kind of method inside InspectorBrowser class to pass accounts data to HTML

        private void EnumerateAccounts()
        {
            //The problem is here
            Outlook.Accounts accounts = OutlookHost.Session.Accounts;
            foreach (Outlook.Account account in accounts)
            {
                try
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Account: " + account.DisplayName);
                    if (string.IsNullOrEmpty(account.SmtpAddress)
                        || string.IsNullOrEmpty(account.UserName))
                    {
                        Outlook.AddressEntry oAE =
                            account.CurrentUser.AddressEntry
                            as Outlook.AddressEntry;
                        if (oAE.Type == "EX")
                        {
                            Outlook.ExchangeUser oEU =
                                oAE.GetExchangeUser()
                                as Outlook.ExchangeUser;
                            sb.AppendLine("UserName: " +
                                oEU.Name);
                            sb.AppendLine("SMTP: " +
                                oEU.PrimarySmtpAddress);
                            sb.AppendLine("Exchange Server: " +
                                account.ExchangeMailboxServerName);
                            sb.AppendLine("Exchange Server Version: " +
                                account.ExchangeMailboxServerVersion); 
                        }
                        else
                        {
                            sb.AppendLine("UserName: " +
                                oAE.Name);
                            sb.AppendLine("SMTP: " +
                                oAE.Address);
                        }
                    }
                    else
                    {
                        sb.AppendLine("UserName: " +
                            account.UserName);
                        sb.AppendLine("SMTP: " +
                            account.SmtpAddress);
                        if(account.AccountType == 
                            Outlook.OlAccountType.olExchange)
                        {
                            sb.AppendLine("Exchange Server: " +
                                account.ExchangeMailboxServerName);
                            sb.AppendLine("Exchange Server Version: " +
                                account.ExchangeMailboxServerVersion); 
                        }
                    }
                    if(account.DeliveryStore !=null)
                    {
                        sb.AppendLine("Delivery Store: " +
                            account.DeliveryStore.DisplayName);
                    }
                    sb.AppendLine("---------------------------------");
                    Debug.Write(sb.ToString());
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }
        }


How can I get access to OutlookHost to get session?

In main addin class I would use code below but in ADXOlForm HostApplication is not defined.
public Outlook._Application OutlookHost()
        {
            return (HostApplication as Outlook._Application);
        }
Posted 22 Sep, 2020 03:47:34 Top
wxnko




Posts: 2
Joined: 2020-09-22
The solution is here:
public Outlook._Application OutlookHost()
        {
            return (AddinExpress.MSO.ADXAddinModule.CurrentInstance.HostApplication as Outlook._Application);
        }

I don't know why code below passes empty object to JS that's why I hadn't used it.
private void webBrowser_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            var d = webBrowser.Document.DomDocument as mshtml.HTMLDocument;
            try
            {
                dynamic window = d.parentWindow;
                var windowEx = (IExpando)window;
                PropertyInfo p = windowEx.AddProperty("bhoModule");
                p.SetValue(windowEx, AddinExpress.MSO.ADXAddinModule.CurrentInstance, null);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("error adding ie script: " + ex.Message);
            }
        }
Posted 22 Sep, 2020 03:56:42 Top
Andrei Smolin


Add-in Express team


Posts: 17438
Joined: 2006-05-11
Hello,

I suppose you need to use the ObjectForScripting property; see https://docs.microsoft.com/en-us/dotnet/api/system.windows.forms.webbrowser.objectforscripting?view=netframework-4.8.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 23 Sep, 2020 03:40:13 Top