我特林从我的C#(WinForm的)应用程序发送电子邮件至ADRESS前景,但我上线getteing错误如下:我试图在C#中发送电子邮件了InvalidCastException错误
Outlook.MailItem mail =(Outlook.MailItem)_app.CreateItem(Outlook.OlItemType.olMailItem);
我得到了以下错误:
Unable to cast COM object of type ‘Microsoft.Office.Interop.Outlook.ApplicationClass’ to interface type ‘Microsoft.Office.Interop.Outlook._Application’. This operation failed because the QueryInterface call on the COM component for the interface with IID ‘{00063001-0000-0000-C000-000000000046}’ failed due to the following error: Library not registered. (Exception de 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 = '[email protected]";
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发送电子邮件或网络服务器?如果你是从服务器发送它,为什么不切断前景中间人呢? – Takarii
也许[这个问题](http://stackoverflow.com/questions/17810163/outlook-interop-exception-displaying-new-mailitem)可能有帮助吗? –
Takarii ..感谢您的回复。我使用Outlook将邮件发送到另一个Outlook地址。从展望到展望 – Christ