Orchestrator Class Library: EMailService

by Simon Sparks · October 1, 2025

This is a sample of how to create service which extends the BaseService using the Build Tools.

GitHub Repository: https://github.com/SimonSparksUK/Orchestrator

Filename: BaseService.ts


import { ResourceElementAccessor } from "com.vmware.pscoe.library.ts.util/ResourceElementAccessor";
import { BaseService } from "../BaseService";

export class EMailService extends BaseService {
    private strDefaultContentType: string = "text/html; charset=UTF-8";// TO DO - SS - Use a Config Element
    private strEMailFromAddress: string = "no-reply@cloudbuildtools.com";
    private strEMailFromName: string = "No Reply;
    private strSMTPHostFQDN: string = "smtp.office365.com";
    private intSMTPHostPort: number = 587;
    private arrDefaultMimeAttachment: MimeAttachment[] = [];
 
    public sendMessage(strEMailToAddress: string, strEMailSubject: string, strEMailContent: string, strContentType: string = this.strDefaultContentType, arrMimeAttachment: MimeAttachment[] = this.arrDefaultMimeAttachment): boolean {
        let objEmailMessage: EmailMessage = new EmailMessage();
        objEmailMessage.smtpHost = this.strSMTPHostFQDN;
        objEmailMessage.smtpPort = this.intSMTPHostPort;
        objEmailMessage.fromName = this.strEMailFromName;
        objEmailMessage.fromAddress = this.strEMailFromAddress;
        objEmailMessage.toAddress = strEMailToAddress;
        objEmailMessage.subject = strEMailSubject;
        objEmailMessage.addMimePart(strEMailContent, strContentType);

        arrMimeAttachment.forEach((objMimeAttachment: MimeAttachment) => {
            this.objLogger.info(`Adding attachment: ${objMimeAttachment.name} with contentType: ${objMimeAttachment.mimeType}.`);

            objEmailMessage.addMimePart(objMimeAttachment, null);
        });

        this.objLogger.info(`sending mail to host: ${objEmailMessage.smtpHost}:${objEmailMessage.smtpPort}, from:${objEmailMessage.fromAddress}, to:${objEmailMessage.toAddress} contentType:${strContentType}.`);
        
        try {
            objEmailMessage.sendMessage();
            return true;
        } catch (objException) {
            return false;
        }
    };
    
}

Discover more from Cloud Build Tools

Subscribe to get the latest posts sent to your email.

You may also like