0

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

1
  • are you sure it successfully ran outlook? what account did the service run as? Commented Aug 3, 2016 at 11:51

1 Answer 1

2

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).

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Dmitry, Thanks for the info. I am using Outlook.Mail because I can encrypt and sign using mail.PropertyAccessor.SetProperty("schemas.microsoft.com/mapi/proptag/0x6E010003", 0x3); without explicit locate the recipient public key. Another method is recipient upload the certificate to GAL. Please see [link]stackoverflow.com/questions/38395266/…. However, my client object this approach. Any suggestion ?
There is not much you can do in this case - it is either use OOM from a process running as the user, or handle the encryption on your own.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.