2013-09-04 4 views
5

Мне нужно иметь доступ к зарегистрированному в данный момент электронному адресу пользователя с кодом C#.Получить адрес электронной почты Outlook с помощью C#

Мне нужен полный адрес, а не только предполагаемая учетная запись электронной почты (например, [email protected]), хотя это будет работать для большинства клиентов.

Любая помощь будет принята с благодарностью.

+0

Боюсь, я не бьет в данный момент единственное упоминание я мог бы найти было VB и нужна точка в правильном направлении –

+0

Почти все VB конструкции могут быть легко преобразованы в C# - также взгляните вокруг SO, на вопросы, такие как http://stackoverflow.com/questions/4761521/get-the-email-address-of-the-current-user-in-outlook- 2007 может подать заявку на вас – jdphenix

ответ

5

Попробуйте это, из http://msdn.microsoft.com/en-us/library/ff462091.aspx:

using System; 
using System.Text; 
using Outlook = Microsoft.Office.Interop.Outlook; 

namespace OutlookAddIn1 
{ 
    class Sample 
    { 
     public static void DisplayAccountInformation(Outlook.Application application) 
     { 

      // The Namespace Object (Session) has a collection of accounts. 
      Outlook.Accounts accounts = application.Session.Accounts; 

      // Concatenate a message with information about all accounts. 
      StringBuilder builder = new StringBuilder(); 

      // Loop over all accounts and print detail account information. 
      // All properties of the Account object are read-only. 
      foreach (Outlook.Account account in accounts) 
      { 

       // The DisplayName property represents the friendly name of the account. 
       builder.AppendFormat("DisplayName: {0}\n", account.DisplayName); 

       // The UserName property provides an account-based context to determine identity. 
       builder.AppendFormat("UserName: {0}\n", account.UserName); 

       // The SmtpAddress property provides the SMTP address for the account. 
       builder.AppendFormat("SmtpAddress: {0}\n", account.SmtpAddress); 

       // The AccountType property indicates the type of the account. 
       builder.Append("AccountType: "); 
       switch (account.AccountType) 
       { 

        case Outlook.OlAccountType.olExchange: 
         builder.AppendLine("Exchange"); 
         break; 

        case Outlook.OlAccountType.olHttp: 
         builder.AppendLine("Http"); 
         break; 

        case Outlook.OlAccountType.olImap: 
         builder.AppendLine("Imap"); 
         break; 

        case Outlook.OlAccountType.olOtherAccount: 
         builder.AppendLine("Other"); 
         break; 

        case Outlook.OlAccountType.olPop3: 
         builder.AppendLine("Pop3"); 
         break; 
       } 

       builder.AppendLine(); 
      } 

      // Display the account information. 
      System.Windows.Forms.MessageBox.Show(builder.ToString()); 
     } 
    } 
} 
+1

замечательное спасибо, что я использовал правильный скрипт, и эта ссылка помогла много простой проблеме, не включая правильные ссылки, не забудет, что один =) –

Смежные вопросы