当前位置: 首页>>代码示例>>C#>>正文


C# Application.GetNamespace方法代码示例

本文整理汇总了C#中Microsoft.Office.Interop.Outlook.Application.GetNamespace方法的典型用法代码示例。如果您正苦于以下问题:C# Application.GetNamespace方法的具体用法?C# Application.GetNamespace怎么用?C# Application.GetNamespace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Microsoft.Office.Interop.Outlook.Application的用法示例。


在下文中一共展示了Application.GetNamespace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: button1_Click

        private void button1_Click(object sender, RibbonControlEventArgs e)
        {
            Outlook.Application application = new Outlook.Application();
            Outlook.NameSpace ns = application.GetNamespace("MAPI");

            try
            {
                //get selected mail item
                Object selectedObject = application.ActiveExplorer().Selection[1];
                Outlook.MailItem selectedMail = (Outlook.MailItem)selectedObject;

                //create message
                Outlook.MailItem newMail = application.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
                newMail.Recipients.Add(ReadFile());
                newMail.Subject = "SPAM";
                newMail.Attachments.Add(selectedMail, Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem);

                newMail.Send();
                selectedMail.Delete();

                System.Windows.Forms.MessageBox.Show("Spam notification has been sent.");
            }
            catch
            {
                System.Windows.Forms.MessageBox.Show("You must select a message to report.");
            }
        }
开发者ID:jamesfaske,项目名称:Report-Spam,代码行数:27,代码来源:Ribbon1.cs

示例2: Main

    public static void Main(string[] args)
    {
        Outlook.Application application = null;

        application = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
        application = new Outlook.Application();
        Outlook.NameSpace nameSpace = application.GetNamespace("MAPI");

        Outlook.MAPIFolder userFolder = null;
        Outlook.MAPIFolder emailFolder = nameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

        try
        {
            foreach (Outlook.MailItem item in emailFolder.Items)
            {
                if (SearchAttachments(item.Attachments, args[0]))
                {
                    Console.WriteLine(item.Subject);
                    break;
                }

            }
        }
        catch (Exception message)
        {
            Console.WriteLine(message);
        }
    }
开发者ID:perchouli,项目名称:works,代码行数:28,代码来源:read_outlook.cs

示例3: InitializeObjects

 private void InitializeObjects()
 {
     _myApp = new Microsoft.Office.Interop.Outlook.Application();
     _mapiNameSpace = _myApp.GetNamespace("MAPI");
     _mapiFolder = _mapiNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
     
 } 
开发者ID:rcarubbi,项目名称:Carubbi.Components,代码行数:7,代码来源:OutlookInteropReceiver.cs

示例4: GetApplicationObject

        //This function is taken from the MSDN :
        //https://msdn.microsoft.com/en-us/library/office/ff462097.aspx
        public static Outlook.Application GetApplicationObject()
        {
            Outlook.Application application = null;

            // Check if there is an Outlook process running.
            if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
            {
                try
                {
                    // If so, use the GetActiveObject method to obtain the process and cast it to an Application object.
                    application = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
                }
                catch
                {
                    //log to windows logs
                    application = new Outlook.Application();
                    Outlook.NameSpace nameSpace = application.GetNamespace("MAPI");
                    nameSpace.Logon("", "", false, Missing.Value);
                    nameSpace = null;
                }

            }
            else
            {

                // If not, create a new instance of Outlook and log on to the default profile.
                application = new Outlook.Application();
                Outlook.NameSpace nameSpace = application.GetNamespace("MAPI");
                nameSpace.Logon("", "", false, Missing.Value);
                nameSpace = null;
            }

            // Return the Outlook Application object.
            return application;
        }
开发者ID:Alymcgeel,项目名称:ContextSearchHelper,代码行数:37,代码来源:Helper.cs

示例5: OutlookEmailSender2

 public OutlookEmailSender2()
 {
     Outlook.Application olApplication = new Outlook.Application();
     Outlook.NameSpace olNameSpace = olApplication.GetNamespace("mapi");
     olNameSpace.Logon(Type.Missing, Type.Missing, true, true);
     olMailItem = (Outlook.MailItem)olApplication.CreateItem(Outlook.OlItemType.olMailItem);
     olRecipients = olMailItem.Recipients;
     olApplication.ItemSend += new Outlook.ApplicationEvents_11_ItemSendEventHandler(olApplication_ItemSend);
 }
开发者ID:eduardo-salazar,项目名称:sag,代码行数:9,代码来源:OutlookEmailSender2.cs

示例6: OutlookPortal

		public OutlookPortal()
		{
			oApp = new Microsoft.Office.Interop.Outlook.Application();
			oNameSpace = oApp.GetNamespace("MAPI");
			oOutboxFolder = oNameSpace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderOutbox);
			oNameSpace.Logon(null, null, false, false);
			oMailItem =	(Microsoft.Office.Interop.Outlook._MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
			
		}
开发者ID:mind0n,项目名称:hive,代码行数:9,代码来源:OutlookPortal.cs

示例7: Execute

 protected override ActivityExecutionStatus Execute(ActivityExecutionContext context)
 {
     MessageBox.Show("Searching your Inbox");
     Outlook.Application outlookApp = new Outlook.Application();
     Outlook.MAPIFolder oSentItems = outlookApp.GetNamespace("MAPI").GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
     Outlook.Items oItems = oSentItems.Items;
     foreach (Object rawItem in oItems)
     {
         if (rawItem is Outlook.MailItem)
         {
             Outlook.MailItem item = (Outlook.MailItem)rawItem;
             switch (Filter)
             {
                 case (FilterOption.Subject):
                     if ((item.Subject != null) && (item.Subject.Equals(FilterValue)))
                     {
                         MessageBox.Show("Found message with Subject filter value[" + FilterValue + "]:" + item.Body);
                         (this.Parent.Activities[1] as DummyActivity).TitleProperty = item.Subject;
                     }
                     break;
                 case (FilterOption.From):
                     if ((item.SenderName != null) && (item.SenderName.Equals(FilterValue)))
                     {
                         MessageBox.Show("Found message with From filter value[" + FilterValue + "]:" + item.Body);
                         (this.Parent.Activities[1] as DummyActivity).TitleProperty = item.Subject;
                     }
                     break;
                 case (FilterOption.To):
                     if ((item.To != null) && (item.To.Equals(FilterValue)))
                     {
                         MessageBox.Show("Found message with To filter value[" + FilterValue + "]:" + item.Body);
                         (this.Parent.Activities[1] as DummyActivity).TitleProperty = item.Subject;
                     }
                     break;
                 case (FilterOption.CC):
                     if ((item.CC != null) && (item.CC.Equals(FilterValue)))
                     {
                         MessageBox.Show("Found message with CC filter value[" + FilterValue + "]:" + item.Body);
                         (this.Parent.Activities[1] as DummyActivity).TitleProperty = item.Subject;
                     }
                     break;
                 case (FilterOption.Bcc):
                     if ((item.BCC != null) && (item.BCC.Equals(FilterValue)))
                     {
                         MessageBox.Show("Found message with BCC filter value[" + FilterValue + "]:" + item.Body);
                         (this.Parent.Activities[1] as DummyActivity).TitleProperty = item.Subject;
                     }
                     break;
             }
         }
     }
     MessageBox.Show("Done with Execute in EvaluateInboxItems");
     return ActivityExecutionStatus.Closed;
 }
开发者ID:ssickles,项目名称:archive,代码行数:54,代码来源:EvaluateInboxItems.cs

示例8: checkOutlook

 private bool checkOutlook()
 {
     try {
         Outlook._Application app = new Outlook.Application();
         Outlook.NameSpace ns = app.GetNamespace("MAPI");
         Outlook.MAPIFolder f = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
         return f.UnReadItemCount > 0;
     } catch (Exception e) {
         d(e.Message + e.StackTrace);
         return true;
     }
 }
开发者ID:jweather,项目名称:LEDNotifier,代码行数:12,代码来源:Notifier.cs

示例9: Connect

        public void Connect() {
            oApp = OutlookCalendar.AttachToOutlook();
            log.Debug("Setting up Outlook connection.");

            // Get the NameSpace and Logon information.
            NameSpace oNS = oApp.GetNamespace("mapi");

            //Log on by using a dialog box to choose the profile.
            //oNS.Logon("", Type.Missing, true, true); 
            
            //Implicit logon to default profile, with no dialog box
            //If 1< profile, a dialogue is forced unless implicit login used
            exchangeConnectionMode = oNS.ExchangeConnectionMode;
            if (exchangeConnectionMode != OlExchangeConnectionMode.olNoExchange) {
                log.Info("Exchange server version: " + oNS.ExchangeMailboxServerVersion.ToString());
            }
            
            //Logon using a specific profile. Can't see a use case for this when using OGsync
            //If using this logon method, change the profile name to an appropriate value:
            //HKEY_CURRENT_USER\Software\Microsoft\Windows NT\CurrentVersion\Windows Messaging Subsystem\Profiles
            //oNS.Logon("YourValidProfile", Type.Missing, false, true); 

            log.Info("Exchange connection mode: " + exchangeConnectionMode.ToString());
            currentUserSMTP = GetRecipientEmail(oNS.CurrentUser);
            currentUserName = oNS.CurrentUser.Name;
            if (currentUserName == "Unknown") {
                log.Info("Current username is \"Unknown\"");
                if (Settings.Instance.AddAttendees) {
                    System.Windows.Forms.MessageBox.Show("It appears you do not have an Email Account configured in Outlook.\r\n" +
                        "You should set one up now (Tools > Email Accounts) to avoid problems syncing meeting attendees.",
                        "No Email Account Found", System.Windows.Forms.MessageBoxButtons.OK,
                        System.Windows.Forms.MessageBoxIcon.Warning);
                }
            }

            //Get the accounts configured in Outlook
            accounts = oNS.Accounts;
            
            // Get the Calendar folders
            useOutlookCalendar = getDefaultCalendar(oNS);
            if (MainForm.Instance.IsHandleCreated) { //resetting connection, so pick up selected calendar from GUI dropdown
                //***This might be cross thread, so don't rely on MainForm
                MainForm.Instance.cbOutlookCalendars.DataSource = new BindingSource(calendarFolders, null);
                KeyValuePair<String, MAPIFolder> calendar = (KeyValuePair<String, MAPIFolder>)MainForm.Instance.cbOutlookCalendars.SelectedItem;
                calendar = (KeyValuePair<String, MAPIFolder>)MainForm.Instance.cbOutlookCalendars.SelectedItem;
                useOutlookCalendar = calendar.Value;
            }

            // Done. Log off.
            oNS.Logoff();
        }
开发者ID:EduShareGeorgian,项目名称:OutlookGoogleSync,代码行数:51,代码来源:OutlookNew.cs

示例10: OutlookMail

		public OutlookMail()
		{
			//http://www.c-sharpcorner.com/uploadfile/casperboekhoudt/sendingemailsthroughoutlook12052005000124am/sendingemailsthroughoutlook.aspx

			oApp = new Outlook.Application();
			oNameSpace = oApp.GetNamespace("MAPI");
			oNameSpace.Logon(null, null, true, true);

			//Calender: Outlook.OlDefaultFolders.olFolderCalendar 
			//Contacts: Outlook.OlDefaultFolders.olFolderContacts 
			//Inbox: Outlook.OlDefaultFolders.olFolderInbox 

			oOutboxFolder = oNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox);
		}
开发者ID:sanyaade-fintechnology,项目名称:NinjaTrader,代码行数:14,代码来源:OutlookMail.cs

示例11: ThisAddIn_Startup

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            // Create Application class and get namespace
            Outlook.Application outlook = new Outlook.Application();
            Outlook.NameSpace ns = outlook.GetNamespace("Mapi");

            object _missing = Type.Missing;
            ns.Logon(_missing, _missing, false, true);

            // Get Inbox information in objec of type MAPIFolder
            Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

            int i = inbox.Items.Count;
            MessageBox.Show("Message count: " + i);
        }
开发者ID:ZeeshanShafqat,项目名称:Aspose_Email_NET,代码行数:15,代码来源:ThisAddIn.cs

示例12: sendEmail

 private void sendEmail(EmailObject eml, bool errEmail = false)
 {
     string myDate = DateTime.Today.ToString("MMMM dd, yyyy");
     Outlook._Application _app = new Outlook.Application();
     Outlook._NameSpace _ns = _app.GetNamespace("MAPI");
     System.Threading.Thread.Sleep(5000); //wait for app to start
     Outlook.MailItem _mail = (Outlook.MailItem)_app.CreateItem(Outlook.OlItemType.olMailItem);
     try
     {
         int fileCount = 0;
         if (qryNames != null)
         {
             foreach (var qryName in qryNames)
             {
                 if (System.IO.File.Exists(AttachmentLocation + qryName))
                 {
                     _mail.Attachments.Add(AttachmentLocation + qryName);
                     fileCount++;
                 }
             }
         }
         _mail.Subject = myDate + " " + eml.Subject;
         _mail.To = eml.To;
         _mail.CC = eml.CC;
         _mail.Body = eml.Body;
         _mail.Importance = Outlook.OlImportance.olImportanceNormal;
         System.Threading.Thread.Sleep(5000); //wait for application to catch up with mail object
         ((Outlook.MailItem)_mail).Send();
         _ns.SendAndReceive(true); //send and receive
         _mail.Close(Outlook.OlInspectorClose.olDiscard);
         System.Threading.Thread.Sleep(5000); //wait for application to catch up with mail object
         _app.Quit();
         isSuccessful = true;
     }
     catch (COMException cEx)
     {
         if (cEx.Message != "The item has been moved or deleted.")
         {
             ErrorHandler.Handle(cEx);
             isSuccessful = false;
         }
     }
     catch (Exception x)
     {
         ErrorHandler.Handle(x);
         isSuccessful = false;
     }
 }
开发者ID:MattPaul25,项目名称:SQLSenderForm,代码行数:48,代码来源:GenerateEmail.cs

示例13: Main

        static void Main(string[] args)
        {
            Outlook.Application app = null;

            if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
            {
                app = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
                Console.WriteLine("Got the magical active outlook object! Hooray!");
            }
            else
            {
                app = new Outlook.Application();
                Outlook.NameSpace ns = app.GetNamespace("MAPI");
                ns.Logon("", "", Missing.Value, Missing.Value);
                ns = null;
                Console.WriteLine("Created a new session!");
            }

            if (app != null)
            {
                Outlook.NameSpace ns = app.GetNamespace("MAPI");
                foreach (Outlook.MAPIFolder folder in ns.Folders)
                {
                    Console.WriteLine("{0}", folder.Name);
                    foreach (Outlook.MAPIFolder innerFolder in folder.Folders)
                    {
                        Console.WriteLine("++{0}", innerFolder.Name);
                        if (innerFolder.Name == "Magical Inbox")
                        {
                            Outlook.Items items = innerFolder.Items;
                            foreach (Outlook.MailItem item in items)
                            {
                                Console.WriteLine("++--{0}", item.Subject);
                                foreach (Outlook.Attachment att in item.Attachments)
                                {
                                    Console.WriteLine("++--..{0}: {1}", att.FileName, att.PathName);
                                }
                            }
                        }
                    }
                }

                Console.In.Read();

                ns.Logoff();
            }
        }
开发者ID:DrSamNemo,项目名称:BIgglesOne,代码行数:47,代码来源:Program.cs

示例14: ThisAddIn_Startup

        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            string FilePath = @"E:\Aspose\Aspose VS VSTO\Sample Files\ExportEmail.msg";

            // Create Application class and get namespace
            Outlook.Application outlook = new Outlook.Application();
            Outlook.NameSpace ns = outlook.GetNamespace("Mapi");

            object _missing = Type.Missing;
            ns.Logon(_missing, _missing, false, true);

            // Get Inbox information in objec of type MAPIFolder
            Outlook.MAPIFolder inbox = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);

            Outlook.MailItem item = inbox.Items[0];
            item.SaveAs(FilePath,_missing);
        }
开发者ID:ZeeshanShafqat,项目名称:Aspose_Email_NET,代码行数:17,代码来源:ThisAddIn.cs

示例15: getFromMsOutlook_Click

        private void getFromMsOutlook_Click(object sender, EventArgs e)
        {
            Outlook.Application oApp = new Outlook.Application();
            Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");
            Outlook.MAPIFolder oContactsFolder = oNS.PickFolder();
            string filter = "[MessageClass] = \"IPM.Contact\"";
            Outlook.Items oContactItems = oContactsFolder.Items.Restrict(filter);
            foreach (Outlook.ContactItem oContact in oContactItems)
            {
                if (oContact.Email1Address!=null)
                {
                    if (oContact.Email1Address.Trim()!=""){
                        ListViewItem lt = ListEmails.Items.Add(oContact.Email1Address);
                        lt.SubItems.Add(oContact.FullName);
                    }

                }
            }
        }
开发者ID:BoiDM,项目名称:MailSender,代码行数:19,代码来源:Form1.cs


注:本文中的Microsoft.Office.Interop.Outlook.Application.GetNamespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。