Purpose Generate an Outlook email 1. Send as plain text 2. Send as HTML with embedded image |
Solution
Important hint for the "new outlook"
InputScript // build email body 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 // call up outlook via a JavaScript function "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); 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" _
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"); 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 |