如何使用共享邮箱在C#中发送programmaticaly的电子邮件? [英] How to send email programmaticaly in in C# using a shared mailbox?

查看:140
本文介绍了如何使用共享邮箱在C#中发送programmaticaly的电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的第一个问题是,当我登录Outlook时,我的登录默认为我的个人电子邮件。但是,我想切换到我的共享邮箱并从中发送电子邮件。我希望FROM属性能反映共享邮箱名称和
我想在代码中执行此操作,但到目前为止还不成功。到目前为止,这是基本代码,我被困在这里。我想添加将打开共享邮箱的默认代码行,以便在应用程序运行时,使用邮箱名称填充FROM字段。

MY first question though is when I log in to Outlook, my login defaults to my personal email. However, I would like to switch to my shared  mailbox and send email from it. I expect that the FROM property would reflect the Shared Mailbox name and I'd like to do this in code but so far unsuccessful. Here's the basic code so far I'm stuck here. I would like to add the line of code that will open the shared mailbox and defaults to it so that when the app runs it populates the FROM field with mailbox name.

我使用Microsoft Office Interop Outlook库。谢谢

I use the Microsoft office Interop Outlook library. Thanks

//创建Outlook应用程序



             ;    Outlook.Application oApp =新Outlook.Application();


                Outlook.Application oApp = new Outlook.Application();

             &NBSP ;  Outlook.NameSpace ONS = oApp.GetNamespace(QUOT; MAPI");

                Outlook.NameSpace oNS = oApp.GetNamespace("mapi");

                 oNS.Logon(Missing.Value,Missing.Value,真实,TRUE);

            &NBSP ;     Outlook.MailItem OMSG =(Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

          &NBSP ;     //设置主题。

                oMsg.Subject =" Send Email" ;;
                 oMsg.HTMLBody = sHtml;

                oNS.Logon(Missing.Value, Missing.Value, true, true);
                  Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
                // Set the subject.
                oMsg.Subject = "Send Email";
                 oMsg.HTMLBody = sHtml;

                //添加收件人。

                Outlook.Recipients oRecips =(Outlook.Recipients)oMsg.Recipients;

                 // TODO:如果需要更改收件人下一行

                 Outlook.Recipient oRecip =(Outlook.Recipient)oRecips.Add(QUOT; xxxcom.off");

                 oRecip.Resolve();

                // Add a recipient.
                Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
                // TODO: Change the recipient in the next line if necessary.
                Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add("xxxcom.off");
                oRecip.Resolve();

                //发送<

                oMsg.Send();

                // Send. <
                oMsg.Send();

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP; //注销。

                oNS.Logoff();

                // Log off.
                oNS.Logoff();

推荐答案

Hello George,

Hello George,

您需要拥有足够的权限/权限才能这样做。您可以使用  SentOnBehalfOfName   属性
仅在Exchange个人资料/帐户的情况下才有意义。此外,您需要具有代表其他人发送所需的权限。请参阅  使用SentOnBehalfOfName发出
  进行类似的讨论。

You need to have sufficient rights/permissions for doing so. You can use the SentOnBehalfOfName property which makes sense only in case of Exchange profiles/accounts. Moreover, you need to have the required permissions to send on behalf of another person. See Issue with SentOnBehalfOfName for a similar discussion.

如果您在个人资料中配置了多个帐户,则可以使用  SendUsingAccount <跨度>  property
,它允许一个Account对象代表发送MailItem的帐户。

In case if you have multiple accounts configured in the profile you can use the SendUsingAccount property which allows to an Account object that represents the account under which the MailItem is to be sent.


这篇关于如何使用共享邮箱在C#中发送programmaticaly的电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆