IdentityIQ 8.2 EmailFileAttachment: How to add attachment to email w/o renaming the attachment

Hi Everyone,

I am having some trouble with an attachment configuration I have setup to go with an email sent during an access request.  All the examples I have seen I have to rename the attachment.  Currently I am renaming the attachment according to a variable(identityDisplayName).  Instead of renaming I just want to leave the name whatever the document is named when the requestor uploads it to the request. Any suggestions?

EmailFileAttachment mailAttachment = new EmailFileAttachment(identityDisplayName + “.pdf”, MimeType.MIME_PDF, pdfDecrypted);
options.addAttachment(mailAttachment);

Try this it might help

String fileName = “C://apache-tomcat//webapps//identityiq//images//example.pdf”;

File file = new File(fileName);

Path pdfPath = Paths.get(fileName);

byte[] fileData = Files.readAllBytes(pdfPath);

EmailFileAttachment attachment = new EmailFileAttachment(“example.pdf”, EmailFileAttachment.MimeType.MIME_PDF, fileData);

options.addAttachment(attachment);

Thanks

D

Hi @dreddy17 ,

Thanks for the response.  Looking at the suggestion, in EmailFileAttachment attachment = new EmailFileAttachment(“example.pdf”, EmailFileAttachment.MimeType.MIME_PDF, fileData);

it seems you’re still setting a static attachment name to “example.pdf”

Was finally able to get this.  Took an extra set of eyes to help me with this. Pulled some guidance from Java Docs.  I used attached.getName() to pull the value of the attachment at the time it is uploaded into SaiLpoint.  See below for more of the code to create the template, attachment..and send it all as one email.  Enjoy.

<Script>
<Source>
import sailpoint.object.Identity;
import sailpoint.object.EmailTemplate;
import sailpoint.object.EmailOptions;
import sailpoint.object.Attachment;
import sailpoint.service.AttachmentService;
import sailpoint.object.EmailFileAttachment;
import sailpoint.object.EmailFileAttachment.MimeType;
import sailpoint.object.EmailFileAttachment.*;
import sailpoint.object.ProvisioningPlan.*;
import sailpoint.object.ProvisioningProject.*;
import sailpoint.service.AttachmentDTO;
import org.apache.log4j.Logger;
import sailpoint.integration.Base64;
import sailpoint.api.SailPointContext;
import java.nio.charset.StandardCharsets;

String supName = IdentityModel.get(“supName”);

Identity supervisor = context.getObjectById(Identity.class, supName);
String supervisorName = supervisor.getName();

EmailTemplate emailtemp = context.getObjectByName(EmailTemplate.class, “SET EMAIL TEMPLATE NAME HERE”);
EmailOptions options = new EmailOptions();

options.setTo(supervisor.getEmail());

Attachment attached = context.getObjectById(Attachment.class, attachmentId);

byte[] pdfDecrypted = AttachmentService.decrypt(attached.getContent(), context);

EmailFileAttachment mailAttachment = new EmailFileAttachment(attached.getName() + “.pdf”, MimeType.MIME_PDF, pdfDecrypted);

options.addAttachment(mailAttachment);

context.sendEmailNotification(emailtemp, options);
}
context.decache(emailtemp);
context.decache(supervisor);
return supervisorName;

</Source>
</Script>

How are you getting the attachmentId parameter for your Attachment object?