【发布时间】:2016-12-11 20:13:21
【问题描述】:
我正在尝试从我的 C#(winform) 应用程序向地址 Outlook 发送一封电子邮件,但我在下面的行中遇到了错误:
Outlook.MailItem mail =(Outlook.MailItem)_app.CreateItem(Outlook.OlItemType.olMailItem);
我收到以下错误:
无法转换 COM 类型的对象 'Microsoft.Office.Interop.Outlook.ApplicationClass' 到接口类型 'Microsoft.Office.Interop.Outlook._Application'。此操作失败 因为接口的 COM 组件上的 QueryInterface 调用 IID 为“{00063001-0000-0000-C000-000000000046}”失败,原因是 以下错误:库未注册。 (HRESULT 例外: 0x80040155)
我的完整代码是:
void SendEmailAuto()
{
try
{
OpenFileDialog attachment = new OpenFileDialog();
attachment.Title = "Select a file to send";
attachment.ShowDialog();
Outlook._Application _app = new Outlook.Application();
Outlook.MailItem mail =mail= (Outlook.MailItem)_app.CreateItem(Outlook.OlItemType.olMailItem);
mail.To = 'paul.m@adt.org";
mail.Subject = "Text";
mail.Body = "Funding Request Team";
if (attachment.FileName.Length > 0)
{
mail.Attachments.Add(attachment.FileName, Outlook.OlAttachmentType.olByValue, 1, attachment.FileName);
mail.Importance = Outlook.OlImportance.olImportanceHigh;
((Outlook.MailItem)mail).Send();
}
else
{
MessageBox.Show("You are kindly requested to attach a document.", "MISSING FILE", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
catch (Exception ex)
{
string msg = ex.Message;
}
}
【问题讨论】:
-
您是使用 Outlook 发送电子邮件,还是使用网络服务器?如果您还是从服务器发送它,为什么不直接删除 Outlook 中间人?
-
也许this question 可能有帮助?
-
Takarii..感谢您的回复。我正在使用 Outlook 向另一个 Outlook 地址发送邮件。从展望到展望