15-02-24 02:21 PM
Hello Team,
I have a requirement to convert .msg files in specific folders to pdf. I have a C# code which uses the HTML from the email and converts to pdf. The drawback is that the images are not printed in pdf. So I am wondering is there any code and dll packages that could replicate the operation of printing the email like the way one normally prints email(File->Print->PrintToPDF).
I have tried using the below links but couldn't implement it in BP
How to convert outlook email (.msg) to pdf c# ? - Microsoft Q&A
How do I convert a .msg file to a .pdf file using C#? - CodeProject
Please let me know
17-02-24 10:09 AM
Hi Susamay
Recently I have been working on something very similar.
I have uploaded a file, that I am still testing. I will tell you what it is supposed to do.
Converts an Outlook msg file to pdf format.
If no output path is provided the code will create a .pdf file in the same directory as your .msg file. The path to the .pdf file will be returned as an output of the action.
Please note that this code requires the Microsoft Outlook and Word applications to be installed on your machine.
The .html file created during the process will be deleted at the end.
Feel free to modify is as needed.
19-02-24 01:57 PM
Hi Susamay
You can please ignore the 1st attachment, it does not work, some of the libraries were missing.
You can try this second attempt.
Kind regards
Gavin
19-02-24 03:43 PM
Thank you so much Galvin. I am trying to run the code but it gives the below error
Operation aborted (Exception from HRESULT: 0x80004004 (E_ABORT))
19-02-24 03:58 PM
I tried running the code in a virtual machine and it gives the the below error
"Cannot create ActiveX component."
19-02-24 06:02 PM
Hi Susamay
One of my colleagues said he experienced the same thing.
As I said, this is something new I am trying. I have it working on a BPC platform. My colleague says it works on one of our clients' environments as well, but not on his local machine.
However he says if Outlook is open, it does work. I am trying to find out what the differences are in the environments.
Kind regards
Gavin
19-02-24 06:26 PM
Hi Susamay
Can you try the following:
Microsoft.Office.Interop.Outlook.dll
into the Blue Prism folder1.20-02-24 04:32 PM
Hi Gavin,
Thank you so much for your support. I found the reason why the error was thrown. Its because of security policies. Its working fine in my personal machine since I am the administrator. However, for my office laptop the security policies are restricting it from happening at first place.
Below is the article for reference
Program is trying to send an e-mail message on your behalf - Outlook | Microsoft Learn
After referring to the article I believe the below change needs to be implemented as an administrator
Found out that it was blocked by the following policy: HKEY_CURRENT_USER\Software\Policies\Microsoft\office\16.0\outlook\security\promptoomsaveas
The key was set to 0 = Automatically Deny. Changing the key to 2 = Automatically Approve solved the problem
Could you try in that machine where it is not working? I hope it will work
------------------------------
Susamay Halder Consultant
Consultant
Bruce Power
+1(437)217-1086
------------------------------
21-02-24 06:15 AM
Hi Susamay
Thanks for the feedback much appreciated. I hope the Object helps.
Kind regards
Gavin