Generate draft email in Outlook with shell script.

Hi All,

Is there any way to create a draft mail with HTML body in Outlook using Shell script.

If by shell script you mean VBS script, then probably. Yes, you can install Cygwin, and that does allow you to do some shell scripting. But if you are running something on a Windows machine, then you should probably use a Windows tool like the Visual Basic Scripting (VBS) tool. You can probably also create and send HTML emails just using Perl and the MIME::Lite libraries. But if you do that you don't need Outlook and it doesn't matter what client or email system someone uses when they receive the email.

This is quite easy to achieve using powershell:

$ol = New-Object -comObject Outlook.Application 
$ns = $ol.GetNameSpace("MAPI")

$Mail = $ol.CreateItem(0)
$Mail.Recipients.Add("to_person@domain.com")  
$Mail.Subject = "Testing email created from powershell"  
$Mail.HTMLBody = "<HTML><H2 style=""FONT-FAMILY: Tahoma, Geneva, Sans-serif;"">My HTML email.</H2><BODY>My body.</BODY></HTML>"
$Mail.save()
1 Like