如何在名称为 Space C#2003 的 outlook 中添加新帐户

how to add new account in outlook with Name Space C#2003

public void sendEMailThroughOUTLOOK()
{
        if(MessageBox.Show(PublicFunction.L_Get_Msg("msg",28),"MessageBox",MessageBoxButtons.OKCancel)== DialogResult.OK)
        {
            try
            {
                // Create the Outlook application.
                Outlook.Application oApp = new Outlook.Application();
                //set default account send mail
                Outlook.Account account = GetAccountForEmailAddress(oApp,"glintonvn@gmail.com");
                // Create a new mail item.
                Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
                // Set HTMLBody. 
                //oMsg.HTMLBody= "<html> <p style=font size:200%>"+PublicFunction.L_Get_Msg("msg",29)+"<br/>"+ PublicFunction.L_Get_Msg("msg",30)+"</p> </html>";
                oMsg.HTMLBody= txtSubject.Text;
                if(txtSubject.Text.Length < 1)
                {
                    MessageBox.Show(PublicFunction.L_Get_Msg("msg",29));
                    return;
                }
                //Add an attachment.
                String sDisplayName = "MyAttachment";
                int iPosition = (int)oMsg.Body.Length + 1;
                int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
                //now attached the file
                string fileName = Application.StartupPath + @"\Reports\RPTTienDoCongViec.xls";
                Outlook.Attachment oAttach = oMsg.Attachments.Add(fileName, iAttachType, iPosition, sDisplayName);
                oMsg.Subject = PublicFunction.L_Get_Msg("msg",34)+ DateTime.Now.ToString("yyyy-MM-dd");
                // Add a recipient                      
                Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
                char [] catkytu = {','};
                string ThoaiSendEmail ="";
                string [] mailsend = txtEmail.Text.Split(catkytu);

                for(int Thoaiitem = 0; Thoaiitem < mailsend.Length;Thoaiitem++ )
                {
                    ThoaiSendEmail = mailsend[Thoaiitem].ToString();

                    foreach (string recipient in new string[] {ThoaiSendEmail} )
                    {

                        Microsoft.Office.Interop.Outlook.Recipient oRecip = (Microsoft.Office.Interop.Outlook.Recipient)oRecips.Add(recipient);
                        oRecip.Resolve();
                    }
                }
                oMsg.SendUsingAccount = account;
                oMsg.Send();
                oRecips = null;
                oMsg = null;
                oApp = null;
                MessageBox.Show(PublicFunction.L_Get_Msg("msg",32));

            }
            catch 
            {
                MessageBox.Show(PublicFunction.L_Get_Msg("msg",33));
            }
        }
        else return;
    }

    public void sendEMailMTNLLD()
    {       
        try
        {

            // Create the Outlook application.
            Outlook.Application oApp = new Outlook.Application();
            Outlook.NameSpace  NS = oApp.GetNamespace("MAPI");
            NS.Logon("glintonvn@gmail.com","pass",true,true);
            // Create a new mail item.              
            Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
            // Set HTMLBody. 
            oMsg.HTMLBody= "<html> <p style=font size:200%>Dear Patrick<br/>"+PublicFunction.L_Get_Msg("msg",30)+"</p> </html>";
            //Add an attachment.
            String sDisplayName = "";
            int iPosition = (int)oMsg.Body.Length + 1;
            int iAttachType = (int)Outlook.OlAttachmentType.olByValue;
            //now attached the file
            string fileName = Application.StartupPath + @"\Reports\RPTTienDoCongViec.xls";
            Outlook.Attachment oAttach = oMsg.Attachments.Add(fileName, iAttachType, iPosition, sDisplayName);
            oMsg.Subject = "Dear Patrick";
            // Add a recipient                      
            Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;           
            foreach (string recipient in new string[] {"thoai@glinton.com.tw"/*"patrick@glinton.com.tw"*/} )
            {                                           
                Microsoft.Office.Interop.Outlook.Recipient oRecip = (Microsoft.Office.Interop.Outlook.Recipient)oRecips.Add(recipient);
                oRecip.Resolve();
            }

            Outlook.Account account = GetAccountForEmailAddress(oApp,"glintonvn@gmail.com");
            oMsg.SendUsingAccount = account;
            oMsg.Send();
            oRecips = null;
            oMsg = null;
            oApp = null;
            NS = null;

        }//end of try block
        catch 
        {
            MessageBox.Show(PublicFunction.L_Get_Msg("msg",33));
        }

    }

    public static Outlook.Account GetAccountForEmailAddress(Outlook.Application oApp, string smtpAddress)
    {
        Outlook.Accounts accounts = oApp.Session.Accounts;
        foreach (Outlook.Account account in accounts)
        {
            if (account.SmtpAddress == smtpAddress)
            {
                return account;
            }
        }
        throw new System.Exception(string.Format("No Account with SmtpAddress: {0} exists!", smtpAddress));
    }

Outlook 对象模型不提供任何创建新帐户的方法或属性。您可以添加新商店,而不是帐户。请参阅命名空间 class 的 AddStoreEx 方法,它将指定格式的个人文件夹文件 (.pst) 添加到当前配置文件。

要创建新配置文件,您需要使用低级 API - 扩展 MAPI。 How to create MAPI profiles without installing Outlook article. See IProfAdmin::CreateProfile 中描述了整个过程以获取更多信息。