您好我正在更新我们在办公室使用的UWP应用程序。
在我们使用它发送电子邮件之前,它使用的是Windows.ApplicationModel.Email.EmailMessage
但是我真的有限。所以我想用Microsoft.Office.Interop.Outlook
代替直接用outlook
我的测试代码看起来像这样。
try
{
List<string> lstAllRecipients = new List<string>();
//Below is hardcoded - can be replaced with db data
lstAllRecipients.Add("info@test.com");
//lstAllRecipients.Add("chandan.kumarpanda@testmail.com");
Outlook.Application outlookApp = new Outlook.Application();
Outlook._MailItem oMailItem = (Outlook._MailItem)outlookApp.CreateItem(Outlook.OlItemType.olMailItem);
Outlook.Inspector oInspector = oMailItem.GetInspector;
// Thread.Sleep(10000);
// Recipient
Outlook.Recipients oRecips = (Outlook.Recipients)oMailItem.Recipients;
foreach (String recipient in lstAllRecipients)
{
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(recipient);
oRecip.Resolve();
}
////Add CC
//Outlook.Recipient oCCRecip = oRecips.Add("THIYAGARAJAN.DURAIRAJAN@testmail.com");
//oCCRecip.Type = (int)Outlook.OlMailRecipientType.olCC;
//oCCRecip.Resolve();
//Add Subject
oMailItem.Subject = "Test Mail";
// body, bcc etc...
//Display the mailbox
oMailItem.Display(true);
}
catch (Exception objEx)
{
await new MessageDialog(objEx.Message, "Error email to Outlook").ShowAsync();
}
我已将Microsoft.Office.Interop.Outlook.dll版本添加到应用程序中,方法是在C:\ Windows \ assembly \ GAC_MSIL \ Microsoft.Office.Interop.Outlook \ 15.0.0.0__71e9bce111e9429c \ Microsoft.Office中找到它。 Interop.Outlook.dll是文件版本15.0.4569.1507
我的问题是当我运行代码时出现以下错误
由于以下错误,使用CoCreateInstanceFromApp使用CLSID {0006F03A-0000-0000-C000-000000000046}创建COM组件的实例失败:80040154未注册类(HRESULT异常:0x80040154(REGDB_E_CLASSNOTREG))。请确保您的COM对象位于允许的CoCreateInstanceFromApp列表中。
我猜我必须在appxmanifest中添加一个引用,但我怎么也弄不清楚。