Problem
There are requirements like you are writing a run rule task to do some activities in sailpoint like cleanup etc , And before making changes , you want to verify what is detected by code , Email can be sent with Attached File . It’s just an Example , There can be multiple requirements .
Diagnosis
In Order to handle such Requirements , Email with Attached file can be sent from sailpoint .
Solution
I am providing below sample code which can be used . It can be customized as per the requirements , like you can send multiple files etc .
import sailpoint.object.EmailFileAttachment;
import sailpoint.object.EmailOptions;
import sailpoint.object.EmailTemplate;
import java.util.HashMap;
import java.util.Map;
public void sendMail()
{
try
{
//Preparing File Data
StringBuilder fileData = new StringBuilder();
fileData.append("Column1|Column2|Column3 \r\n");
fileData.append("test1|test2|test3 \r\n");
//Variables which is needed in Email Template as per requirement
Map optionsMap = new HashMap();
optionsMap.put("subject", "Test Email");
//Fetching Email Template
EmailTemplate emailTemplate = context.getObject(EmailTemplate.class, "Sample Email Template");
EmailOptions options = new EmailOptions();
options.setTo("test@abc.com");
options.setCc("test1@abc.com");
options.setVariables(optionsMap);
//Preparing Attachment
String fileName="SampleFile.txt";
byte[] parsedFileData;
parsedFileData = fileData.toString().getBytes("UTF-8");
EmailFileAttachment attachment = new EmailFileAttachment(fileName, EmailFileAttachment.MimeType.MIME_PLAIN, parsedFileData);
options.addAttachment(attachment);
//Sending Email
context.sendEmailNotification(emailTemplate, options);
}
catch (Exception e)
{
log.error("Exception while sending Email:: "+e)
}
}
sendMail();