Purpose
Generate an Outlook email

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

            };
        };
    };
};

Components
InputAssistant + Controls