AddEmail ActiveX can be used with any environment that supports JScript. Windows has built-in JScript support and can execute JScript files that have .JS extension. To use AddEmail ActiveX from JScript code create SmtpMail object and send a message using SimpleSendScriptable, SimpleSendAttachmentScriptable or SendScriptable. Please use code snapshots below to get started.
Snapshot 1: simple text email.
var objSmtpMail, strError, numResultCode;
objSmtpMail = new ActiveXObject("AddEmail.SmtpMail");
objSmtpMail.SmtpServer = "mail.myserver.com";
objSmtpMail.SmtpUsername = "jsmith";
objSmtpMail.SmtpPassword = "mypassword";
numResultCode = objSmtpMail.SimpleSendScriptable("jsmith@myserver.com", "jane@someserver.com;james@someserver.com", "test", "Test message", strError);
if (numResultCode == 0)
{
WScript.Echo("Sent successfully!");
}
else
{
strError = objSmtpMail.GetLastErrorDescription();
WScript.Echo(strError);
}
Snapshot 2: text email with attachments.
var objSmtpMail, strError, numResultCode;
objSmtpMail = new ActiveXObject("AddEmail.SmtpMail")
objSmtpMail.SmtpServer = "mail.myserver.com";
objSmtpMail.SmtpUsername = "jsmith";
objSmtpMail.SmtpPassword = "mypassword";
numResultCode = objSmtpMail.SimpleSendAttachmentScriptable("jsmith@myserver.com", "jane@someserver.com;james@someserver.com", "test", "Test message", "c:\\files\\doc1.pdf;c:\\files\\doc2.pdf", strError);
if (numResultCode == 0)
{
WScript.Echo("Sent successfully!");
}
else
{
strError = objSmtpMail.GetLastErrorDescription();
WScript.Echo(strError);
}
Snapshot 3: HTML message with attachments.
// Create message and setup subject and body
objMailMessage = new ActiveXObject("AddEmail.MailMessage");
objMailMessage.MessageBodyFormat = 1; //HTML format
objMailMessage.MessageSubject = "test";
objMailMessage.MessageBody = "<html><body><b>Testing...</b></body></html>";
// Add first attachment
objMailAttachment = new ActiveXObject("AddEmail.MailAttachment");
objMailAttachment.File = "c:\\files\\doc1.pdf";
objMailMessage.AddAttachment(objMailAttachment);
// Add second attachment
objMailAttachment = new ActiveXObject("AddEmail.MailAttachment");
objMailAttachment.File = "c:\\files\\doc2.pdf";
objMailMessage.AddAttachment(objMailAttachment);
Please refer to the Reference section of this manual for detailed description of AddEmail objects, methods and properties. Included JScript samples provide code snapshots for common operations such as sending text e-mails, sending HTML e-mails, adding attachments to e-mails.