无法通过Outlook服务从Outlook发送电子邮件。 [英] Un able to send email through outlook from windows service.

查看:188
本文介绍了无法通过Outlook服务从Outlook发送电子邮件。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用下面的代码发送一封由windows服务调用的电子邮件但是我得到了下面提到的错误,我无法修复此问题,请帮助!!!!!!!



由于以下错误,检索CLSID为{0006F03A-0000-0000-C000-000000000046}的组件的COM类工厂失败:80080005服务器执行失败(HRESULT异常:0x80080005(CO_E_SERVER_EXEC_FAILURE))。



使用System;

使用System.Collections.Generic;

使用System.Linq;

使用System.Text;

使用System.Net.Mail;

使用System.Net;

使用Outlook = Microsoft .Office.Interop.Outlook;

使用System.Runtime.InteropServices;



命名空间EmailSender

{

公共类电子邮件程序

{

//向Outlook发送电子邮件的方法

public static void sendEMailThroughOUTLOOK(string emailaddress ,字符串CaseNumber)

{

//创建Outlook应用程序。

Outlook.Application oApp = new Outlook.Application();

//创建一个新的邮件项目。

Outlook.MailItem oMsg =(Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);

// Set HTMLBody。

//添加电子邮件的正文

oMsg.HTMLBody =您好,您的案例编号+ CaseNumber +即将违规,请采取必要的行动;

//添加附件。



oMsg.Subject =测试:案例违规警告+ CaseNumber;

//添加收件人。

Outlook.Recipients oRecips =(Outlook.Recipients)oMsg.Recipients;

//如果在下一行更改收件人必要的。

Outlook.Recipient oRecip =(Outlook.Recipient)oRecips.Add(emailaddress);

oRecip.Resolve();

/ /发送。

oMsg.Send();

//清理。

oRecip = null;

oRecips = null;

oMsg = null;

oApp = null;





} //电子邮件方法结束

}

}

I am using below code to send an email which is called by windows service however I get the below mentioned error and I am unable to fix this , Please help !!!!!!!

Retrieving the COM class factory for component with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the following error: 80080005 Server execution failed (Exception from HRESULT: 0x80080005 (CO_E_SERVER_EXEC_FAILURE)).

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Mail;
using System.Net;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Runtime.InteropServices;

namespace EmailSender
{
public class Emailer
{
//method to send email to outlook
public static void sendEMailThroughOUTLOOK(string emailaddress, string CaseNumber)
{
// Create the Outlook application.
Outlook.Application oApp = new Outlook.Application();
// Create a new mail item.
Outlook.MailItem oMsg = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem);
// Set HTMLBody.
//add the body of the email
oMsg.HTMLBody = "Hello, Your Case Number " + CaseNumber + " is about to breach, Please take necessary action";
//Add an attachment.

oMsg.Subject = "Testing:Case Breach Alert for case " + CaseNumber;
// Add a recipient.
Outlook.Recipients oRecips = (Outlook.Recipients)oMsg.Recipients;
// Change the recipient in the next line if necessary.
Outlook.Recipient oRecip = (Outlook.Recipient)oRecips.Add(emailaddress);
oRecip.Resolve();
// Send.
oMsg.Send();
// Clean up.
oRecip = null;
oRecips = null;
oMsg = null;
oApp = null;


}//end of Email Method
}
}

推荐答案

您不能从Windows服务使用Office Interop。



但是,您可以使用Exchange Web服务。谷歌为它。
You can NOT use Office Interop from a windows service.

You can however use Exchange Web Services. Google for it.


这篇关于无法通过Outlook服务从Outlook发送电子邮件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆