1

I am working on outlook add-in project using Visual studio 2008 for MS Outlook 2007 in C#. Here I am explaining my problem...

I got multiple accounts (3 Accounts) with my outlook 2007. I need to get accounts form Account box in New Mail Message window. When we click New Mail Message, a new window will appear from which we can send a new mail. Here (On this window) we can see Account Dropdown (Left side) under the Send Button. If we have multiple accounts with outlook, we can see all the accounts in Account Drop Down if we click on Account Box. If we click on the particular email, a right mark will appear to that Email Account and a message can bee seen on the top of the Send button is "This message will be sent via xyz@gmail.com".

So, I want to get these email accounts into a string and that particular email account (which has right mark) into another string. I got these 3 email accounts into a string. But, I am not getting the particular email account(which has the right mark when we send a new email).

I am using this code....

using Outlook = Microsoft.Office.Interop.Outlook;

using Office = Microsoft.Office.Core;

using Microsoft.Office.Interop.Outlook;

Outlook._Application myOutlookApp = new Outlook.Application();

Outlook.Accounts myAccounts = myOutlookApp.Session.Accounts;

foreach (Outlook.Account account in myAccounts)
                    {
                        string emailAddress = account.SmtpAddress;
                    }

I am able to get all the accounts from the above code..But, I just want to get the email address which we will use for sending an email at that particular moment..

4

2 回答 2

1

解决方法很简单:

...
your code
...

    foreach (Outlook.Account account in myAccounts)
                        {
                            string emailAddress = account.CurrentUser.AddressEntry.Address;
                        }

电子邮件存储在 CurretUser 对象下的 AddressEntry 属性中。该对象正在考虑中-多么简单:-)

于 2011-09-22T14:43:04.600 回答
1

查看 MailItem SendUsingAccount属性或者您可以按照您所说的从窗口名称中获取它。

马库斯

于 2010-03-16T13:04:28.277 回答