是否可以使用 windows 服务访问 outlook 插件的兑换方法
Is it possible to access redemption method of outlook add in using windows services
我已经在 C# 中创建了 outlook 插件,以使用 redemption(background) 在 SQLite 数据库中存储邮件主题。我们可以访问兑换 method/Class 的 outlook 添加到 windows 服务中。
无法从服务使用 Outlook 对象模型。
你说得对,你不应该使用来自 windows 服务的 Outlook 对象模型。 Considerations for server-side Automation of Office 文章陈述如下:
Microsoft 目前不推荐也不支持从任何无人值守的非交互式客户端应用程序或组件(包括 ASP、ASP.NET 自动化 Microsoft Office 应用程序、DCOM 和 NT 服务),因为当 Office 在此环境中为 运行 时,Office 可能表现出不稳定的行为 and/or 死锁。
如果您正在构建 运行 在服务器端上下文中的解决方案,您应该尝试使用已针对无人值守执行安全设置的组件。或者,您应该尝试找到至少允许 运行 客户端部分代码的替代方案。如果您从服务器端解决方案使用 Office 应用程序,该应用程序将缺少许多 运行 成功所必需的功能。此外,您将承担整体解决方案稳定性的风险。
Redemption 是低级别 API(扩展 MAPI)的包装器。但加载项是 Office 应用程序的一项功能。扩展 MAPI 对它们一无所知。因此,Extended MAPI 周围的任何包装器(在您的情况下为 Redemption)不提供对加载项的访问。
考虑对您的加载项使用任何其他通信方法,例如 - .NET Remoting (WCF)。您可以将托管加载项视为常规 .Net 应用程序。
using Microsoft.Office.Interop.Outlook;
using OutLook = Microsoft.Office.Interop.Outlook;
代码将是
object missing = System.Reflection.Missing.Value;
try
{
OutLook.MAPIFolder fldContacts = null;;
OutLook._Application outlookObj = new OutLook.Application();
string folderName = "Default";
fldContacts = (OutLook.MAPIFolder)outlookObj.Session.GetDefaultFolder(OutLook.OlDefaultFolders.olFolderContacts);
//LOOPIN G THROUGH CONTACTS IN THAT FOLDER.
foreach (Microsoft.Office.Interop.Outlook._ContactItem contactItem in fldContacts.Items)
{
StringBuilder strb = new StringBuilder();
strb.AppendLine((contactItem.FirstName == null) ? string.Empty : contactItem.FirstName);
strb.AppendLine((contactItem.LastName == null) ? string.Empty : contactItem.LastName);
strb.AppendLine(contactItem.Email1Address);
strb.AppendLine(contactItem.Business2TelephoneNumber);
strb.AppendLine(contactItem.BusinessAddress);
//write to text file
StreamWriter sw = null;
sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\LogFile.txt", true);
sw.WriteLine(DateTime.Now.ToString() + ": " + strb.ToString());
sw.Flush();
sw.Close();
}
}
catch (System.Exception ex)
{
throw new ApplicationException(ex.Message);
}
不要在服务中使用 Outlook 对象模型。其次,您假设文件夹中只有 ContactItem
个对象,如果那里有分发列表,您的代码就会中断。
RDO family of Redemption objects可以在服务中使用
我已经在 C# 中创建了 outlook 插件,以使用 redemption(background) 在 SQLite 数据库中存储邮件主题。我们可以访问兑换 method/Class 的 outlook 添加到 windows 服务中。
无法从服务使用 Outlook 对象模型。
你说得对,你不应该使用来自 windows 服务的 Outlook 对象模型。 Considerations for server-side Automation of Office 文章陈述如下:
Microsoft 目前不推荐也不支持从任何无人值守的非交互式客户端应用程序或组件(包括 ASP、ASP.NET 自动化 Microsoft Office 应用程序、DCOM 和 NT 服务),因为当 Office 在此环境中为 运行 时,Office 可能表现出不稳定的行为 and/or 死锁。
如果您正在构建 运行 在服务器端上下文中的解决方案,您应该尝试使用已针对无人值守执行安全设置的组件。或者,您应该尝试找到至少允许 运行 客户端部分代码的替代方案。如果您从服务器端解决方案使用 Office 应用程序,该应用程序将缺少许多 运行 成功所必需的功能。此外,您将承担整体解决方案稳定性的风险。
Redemption 是低级别 API(扩展 MAPI)的包装器。但加载项是 Office 应用程序的一项功能。扩展 MAPI 对它们一无所知。因此,Extended MAPI 周围的任何包装器(在您的情况下为 Redemption)不提供对加载项的访问。
考虑对您的加载项使用任何其他通信方法,例如 - .NET Remoting (WCF)。您可以将托管加载项视为常规 .Net 应用程序。
using Microsoft.Office.Interop.Outlook;
using OutLook = Microsoft.Office.Interop.Outlook;
代码将是
object missing = System.Reflection.Missing.Value;
try
{
OutLook.MAPIFolder fldContacts = null;;
OutLook._Application outlookObj = new OutLook.Application();
string folderName = "Default";
fldContacts = (OutLook.MAPIFolder)outlookObj.Session.GetDefaultFolder(OutLook.OlDefaultFolders.olFolderContacts);
//LOOPIN G THROUGH CONTACTS IN THAT FOLDER.
foreach (Microsoft.Office.Interop.Outlook._ContactItem contactItem in fldContacts.Items)
{
StringBuilder strb = new StringBuilder();
strb.AppendLine((contactItem.FirstName == null) ? string.Empty : contactItem.FirstName);
strb.AppendLine((contactItem.LastName == null) ? string.Empty : contactItem.LastName);
strb.AppendLine(contactItem.Email1Address);
strb.AppendLine(contactItem.Business2TelephoneNumber);
strb.AppendLine(contactItem.BusinessAddress);
//write to text file
StreamWriter sw = null;
sw = new StreamWriter(AppDomain.CurrentDomain.BaseDirectory + "\LogFile.txt", true);
sw.WriteLine(DateTime.Now.ToString() + ": " + strb.ToString());
sw.Flush();
sw.Close();
}
}
catch (System.Exception ex)
{
throw new ApplicationException(ex.Message);
}
不要在服务中使用 Outlook 对象模型。其次,您假设文件夹中只有 ContactItem
个对象,如果那里有分发列表,您的代码就会中断。
RDO family of Redemption objects可以在服务中使用