Hi,
I am trying to access outlook application in my c# code..I
am able to read all mails when I debug..but when I try to access the
same using a Windows service,I can't able to access..I get the
following error..
"Retrieving the COM class factory for component
with CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the
following error: 80080005."...Can anyone help me with this..
Loading

Dharmesh SharmaRank #1,974 · 741 reputationPosted Oct 29, 2009, 11:06 PM EDT
follow the code
create class ClsSend and add the code
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using Microsoft.Office.Core; using OutlookApp = Microsoft.Office.Interop.Outlook; namespace Shreeram { class ClsSend { public void BillSend() { Email outlookEmail = new Email(); outlookEmail.Message.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatPlain; outlookEmail.Message.Importance = Microsoft.Office.Interop.Outlook.OlImportance.olImportanceHigh; string dir = Application.StartupPath; string path = string.Format(@"{0}\{1}", dir, "Bill.pdf"); outlookEmail.Message.Subject = string.Format("Bill: {0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")); outlookEmail.Message.Attachments.Add(path, OutlookApp.OlAttachmentType.olByValue, 1, "Bill.pdf"); outlookEmail.Show(); } } public class Email { /// /// Gets the current instance of Outlook /// OutlookApp.Application _outlookInstance = new Microsoft.Office.Interop.Outlook.Application(); private OutlookApp.MailItem _message; public OutlookApp.MailItem Message { get { return this._message; } set { this._message = value; } } /// /// Constructor, gets current outlook instance /// and creates a blank email message /// public Email() { Initialize(); } private void Initialize() { // create a blank email _message = (OutlookApp.MailItem)_outlookInstance.CreateItem(OutlookApp.OlItemType.olMailItem); // wire up the write event for logging _message.Write += new Microsoft.Office.Interop.Outlook.ItemEvents_10_WriteEventHandler(Message_Write); } /// /// Used for logging after the end user presses the send /// button in Outlook. If you need to log the email that was /// sent to a web service or something else, fill this in. This is /// called after the email is sent via Outlook. /// /// void Message_Write(ref bool Cancel) { // ADD LOGGING HERE IF YOU NEED IT } /// /// Displays the outlook screen and shows the email message. /// public void Show() { _message.Display(false); } } }and this class to ready to send email now
access the class
create object the class
ClsSend send = new ClsSend();
send.
BillSend();if u got answer
click me
dharmesh sharma
Software Engg.
D software pvt