Generate an Outlook email

Use a JavaScript routine that calls up Outlook

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.

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:



// 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"
emailbody _

// return


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");
    var oOMail = oOApp.CreateItem(olMailItem);


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


InputAssistant + Controls