Outlook.MailItem 实例如何知道目标 Exchanger 服务器是什么?

发布于 2024-11-29 12:10:36 字数 727 浏览 1 评论 0原文

我尝试从 C# 应用程序发送电子邮件,我可以通过以下几行轻松完成这项工作(我使用的是 Outlook 2003,并且有我的 Outlook 帐户):

Outlook.ApplicationClass oapp = new Outlook.ApplicationClass();
omessage = oapp.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
omessage.To = "[email protected]";
omessage.Subject = "Send From WinForm";
omessage.Body = "Hi, This message is send from a winform project.";
omessage.Send();

根据上面的代码,电子邮件可以成功发送(尽管发送电子邮件之前会显示一个警告框)。

我的问题是:当我从未在此应用程序中配置我的 Exchange 服务器时,此 omessage 项目如何知道我的 Exchange 服务器在哪里?

是否有任何方法可以从代码端获取 Exchange 服务器名称?因为我确实需要这个服务器地址。

谢谢!

I try to send an email from a C# app, and I can easily finish this job through the following lines (I am using Outlook 2003, and have my outlook account):

Outlook.ApplicationClass oapp = new Outlook.ApplicationClass();
omessage = oapp.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
omessage.To = "[email protected]";
omessage.Subject = "Send From WinForm";
omessage.Body = "Hi, This message is send from a winform project.";
omessage.Send();

Based on the above code, the email can be sent successfully (although there a warning box will be shown before sending the email).

My question is: how does this omessage item knows where my Exchange server is, while I never configured my Exchange Server in this app?

Does there exist any way to get the Exchange Server Name from the code side? Because I really need this server address.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

混吃等死 2024-12-06 12:10:36

您使用 C# Outlook dll\add-in,您的应用程序使用 Outlook 发送此邮件项目。所有属性(包括 Exchange 服务器地址)均在 Outlook 中配置。以下是在代码中公开交换服务器地址的方法:

Outlook.ApplicationClass oapp = new Outlook.ApplicationClass();
Outlook.NameSpace ns = oapp.GetNamespace("MAPI");
ns.Logon();

string ExchangeServer = ns.ExchangeMailboxServerName;

请注意,您必须定义 Outlook.namespace 属性才能通过 MAPI 获取地址

Your using a C# outlook dll\add-in, your application uses outlook to send this mailitem. All properties including the exchange server address, are configured in outlook. Here's a method which exposes the exchange server address in code:

Outlook.ApplicationClass oapp = new Outlook.ApplicationClass();
Outlook.NameSpace ns = oapp.GetNamespace("MAPI");
ns.Logon();

string ExchangeServer = ns.ExchangeMailboxServerName;

Note that you must define a Outlook.namespace property in order to get the address via MAPI

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文