Reputation: 421
I have the code below, it is able to send mail out using Outlook.mail when running as console application.
However, under window service, nothing happened.
No mail in sent box of outlook. Recipients did not received any email.
No exception thrown.
The code as show below.
public void sendEncryptNsign2(String[] recipients, String[] ccs)
{
Outlook.MailItem mail = outlookApp.CreateItem(
Outlook.OlItemType.olMailItem) as Outlook.MailItem;
mail.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x6E010003", 0x3);
//Recipients recips = mail.Recipients;
for (int ii = 0; ii < recipients.Length; ii++)
{
Outlook.Recipient recipTo = mail.Recipients.Add(recipients[ii]);
recipTo.Type = (int)Outlook.OlMailRecipientType.olTo;
recipTo.Resolve();
}
for (int ii = 0; ii < ccs.Length; ii++)
{
Outlook.Recipient recipCc = mail.Recipients.Add(ccs[ii]);
recipCc.Type = (int)Outlook.OlMailRecipientType.olCC;
recipCc.Resolve();
}
// mail.Recipients.ResolveAll();
mail.Subject = "encrypt and signed using tag3";
mail.HTMLBody = "<b>Happy day ?</b><br>tag8 using recipTo.Resolve() recipCc.Resolve(); ";
Library.WriteErrorLog(Library.logfile, "sendEncryptNsign2 calling mail.Send();");
mail.Send();
Library.WriteErrorLog(Library.logfile, "sendEncryptNsign2 after calling mail.Send();");
}
Any help appreciated.
Thanks
Upvotes: 0
Views: 782
Reputation: 66215
Outlook Object Model (just like any other Office app) cannot be used in a service. Your options are straight SMTP, EWS (in case of Exchange), Extended MAPI (C++ or Delphi only) or Redemption (Extended MAPI wrapper, any language - I am its author).
Upvotes: 2