Purpose
Generate an Outlook email

1. Send as plain text
2. Send as HTML with embedded image

Solution
Use a JavaScript routine that calls up Outlook

Example
In a particular transaction we want to generate an email with predefined addressee, cc, subject, email text and attachment list.

For our example we use:

adressee: name@company.com
cc: xyz@abc.com
subject: Project documentation version 15
email text:
Please find attached our new project documentation.

Regards
Mike. B. Smith

attachment: C:\temp\project1208.pdf

You can send the email immediately via Outlook or open up an Outlook window and let the user send the generated email:

 

InputScript

// build email body
// for this example we use a few fixed text lines
// for longer texts you may use a template text file and
// CopyText ... fromTemplate=... whch replaces variables in the text
Clear text[emailbody]
Set V[line] "Please find attached our new project documentation."
CopyText fromString="line" toText="emailbody" -appendline
Set V[line] ""
CopyText fromString="line" toText="emailbody" -appendline
Set V[line] "Regards"
CopyText fromString="line" toText="emailbody" -appendline
Set V[line] "Mike. B. Smith"
CopyText fromString="line" toText="emailbody" -appendline

// attachments
Set text[emailattachments] "C:\temp\project1208.pdf"

// call up outlook via a JavaScript function
CallJS OutlookEmail _
  
"name@company.com" _
   "Project documentation version 15"
_
  
"xyz@abc.com"
_
   
emailbody _
    emailattachments

// return
return

JavaScript

function OutlookEmail(p_to, p_subject, p_cc, 
                          ptxt_body, ptxt_attachments) {

    var olByValue = 1;
    var olMailItem = 0;
    
    var oOApp = guixt.CreateObject("Outlook.Application");
    if (!oOApp)
    {
        alert("Outlook not installed");
        return
    };
    var oOMail = oOApp.CreateItem(olMailItem);

    oOMail.display();

    oOMail.To = p_to;
    oOMail.CC = p_cc;
    oOMail.Subject = p_subject;
    oOMail.Body = guixt.GetText(ptxt_body);

    // attachments 
    if (ptxt_attachments) {
        var attachments = guixt.GetText(ptxt_attachments).split("\n");
        for (var k = 0; k < attachments.length; k++) {
            var attachment = attachments[k];
            if (attachment.length > 0) {
                oOMail.Attachments.Add(attachment, olByValue, 1);

            };
        };
    };
};

Send embedded HTML and images


The text in an email is sent as plain text in most cases. However, it is also possible to use HTML code, e.g. to style the text or to embed images directly. This is possible with the following coding:

Inputscript:

// Send E-Mail with HTML body and embedded image

clear text[emailbody] 

Set V[line] "<html><body><p>Construction Plan A</p>"

CopyText fromString="line" toText="emailbody" -appendline

Set V[line] "<img src='cid:architecture.jpg' width=450>"

CopyText fromString="line" toText="emailbody" -appendline

Set V[line] ""

CopyText fromString="line" toText="emailbody" -appendline

Set V[line] "<br>Best Regards, <br> FredSumit</body></html>"

CopyText fromString="line" toText="emailbody" -appendline

// attachments

Set text[emailattachments] "C:\temp\architecture.jpg" 

// call up outlook via a JavaScript function

CallJS OutlookEmail _

   "name@company.com" _
  
"Project documentation version 15" _
  
"xyz@abc.com" _
   
emailbody _
   
emailattachments

return


JavaScript
function OutlookEmail(p_to, p_subject, p_cc, 
                          ptxt_body, ptxt_attachments) {

    var olByValue = 1;
    var olMailItem = 0;
    
    var oOApp = guixt.CreateObject("Outlook.Application");
    if (!oOApp)
    {
        alert("Outlook not installed");
        return
    };
    var oOMail = oOApp.CreateItem(olMailItem); 
   

    // attachments 
    if (ptxt_attachments) {
        var attachments = guixt.GetText(ptxt_attachments).split("\n");
        for (var k = 0; k < attachments.length; k++) {
            var attachment = attachments[k];
            if (attachment.length > 0) {
                oOMail.Attachments.Add(attachment, olByValue, 0);

            };
        };
    };

    oOMail.To = p_to;
    oOMail.CC = p_cc;
    oOMail.Subject = p_subject;  
   
    oOMail.BodyFormat = 2;
    oOMail.HTMLBody = guixt.GetText(ptxt_body);

    oOMail.display();


};

Components
InputAssistant + Controls