How to convert HTML email to MSG file with PowerShell - windows

I have emails as a ZIP file which contains the HTML version of it (1 html file and optional attachments). How can I convert these html emails to a .msg file using PowerShell?
It seems to be possible to at least work with Outlook:
$outlook = New-Object -ComObject Outlook.Application
And unzipping looks like an easy task according to How to unzip a file in Powershell?
On HTML Email to .MSG there is a similar question, but not really a practical answer so far.

Here is a practical (and very simple) answer using powershell to create a .msg with a HTML body.
$outlook = New-Object -ComObject Outlook.Application
$mailItem= $outlook.CreateItem([Microsoft.Office.Interop.Outlook.OlItemType]::olMailItem)
$mailItem.Subject = "My Subject"
$mailItem.HTMLBody = "<h1>My Title</h1><p>Hello World</p>"
$mailItem.SaveAs("C:\temp\test.msg",[Microsoft.Office.Interop.Outlook.OlSaveAsType]::olMSG)
Please note:
you have a lot of properties in the $mailItem object to customize the object message (have a look at the variable)
you need Outlook client installed on the machine

Related

How to send an email using VBScript without CDO

I can't send email with VBScript because the Cdo resources have been removed.
For example, this line of code does not work because when I open the link, I see that the resource has been removed:
objConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.your.com"
On Microsoft's site it says: "This content is no longer actively maintained."
https://learn.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2003/ms873037(v=exchg.65)
Is there any way to send an email using VBScript where the code doesn't need this kind of reference?

Is there a solution to get a .msg File from the MS Graph API?

I have the task to get several Mails with the Graph API and archive those as .msg files to a server.
Right now, i'm only able to get mails as MIME. Is there a way to transform those into .msg files?
MSG file format is specific to the Windows version of Outlook. Neither Graph nor EWS expose that file format in any way. You can create an MSG file (see How to create ".msg" file without using outlook in mfc?) and import EML into it.
Also note that Outlook will be just as happy to open and display an EML file as an MSG file, so it might make sense to work with EML files, even if they don't expose all the information and MAPI specific properties that an MSG file can store.

Outlook Redemption: Releasing RDOMail from GetMessageFromMsgFile in VBScript

we use VBScript for changing EXIF data of .msg files.
We access msg files using
Set Element = Session.GetMessageFromMsgFile(msgFilePath)
It works fine, exept that the msg file gets locked, so that writing EXIF data to the file fails.
How can I release the msg file (Element), as Marshal.ReleaseComObject() doesn't work within VBScript? Setting Element=Nothing doesn't work either.
Thanks!
Chris
In VB script, just setting the RDOMail object to Nothing will do the job:
set Element = Nothing

Parsing Outlook Emails (.msg) with Mimekit

Im attempting to parse .msg files from outlook to get the MIME content in order to save the file as an eml. I'm using Exchange Web Services to save emls as they come through a journaled inbox on the exchange server, but some emails need to be saved after the fact through an outlook add in, though getting them into an eml/MIME format seems more difficult.
The example on the mimekit github page shows it can parse a msg file, though when I attempt it, a System.FormatException is thrown. Does mimekit support msg parsing?
This is what I am doing right now:
var stream = File.OpenRead(#"C:\example.msg");
var parser = new MimeParser(stream);
var msg = parser.ParseMessage();
Any amount of insight would be incredibly helpful.
MSG format is not MIME - try to open it in Notepad. It is an OLE storage file.
To open IStorage file, use StgOpenStorage.
See Difference between a .msg file and a .eml file

MSword file attachment not working in codeigniter

I am using codeigniter and I am trying to send an email with an attachment, It is working well when i upload pdf but if i upload word file, i receive an empty email, although I have checked the uploading of word file is successful as well, all the uploaded files are in the given path. But there is nothing in email in MSword file case. Here is my code:
//My email function in controller
$attachment = $_FILES['file']['name'];
$this->email->attach('uploads/enquiry/'.$attachment);
You need to provide full path of the file.
so instead of
$this->email->attach('uploads/enquiry/'.$attachment);
try something like this
$this->email->attach(FCPATH.'/uploads/enquiry/'.$attachment);
Try it this way,
You will surely get answer :-
http://ellislab.com/codeigniter%20/user-guide/libraries/file_uploading.html

Resources