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

**URL:** <https://community.sailpoint.com/discuss/t/identityiq-8-2-emailfileattachment-how-to-add-attachment-to-email-w-o-renaming-the-attachment/25851>\
**Category:** Implement & Extend\
**Tags:** access-request-approval, compliance, notification, event-triggers-workflows, identityiq-8.2\
**Created:** [April 12, 2022, 4:06pm UTC](https://community.sailpoint.com/discuss/t/identityiq-8-2-emailfileattachment-how-to-add-attachment-to-email-w-o-renaming-the-attachment/25851 "2022-04-12T16:06:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![deljr1983](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@deljr1983](https://community.sailpoint.com/discuss/u/deljr1983)\
**Post date:** [April 12, 2022, 4:06pm UTC](https://community.sailpoint.com/discuss/t/identityiq-8-2-emailfileattachment-how-to-add-attachment-to-email-w-o-renaming-the-attachment/25851/1 "2022-04-12T16:06:02Z")

</div>

Hi Everyone,

I am having some trouble with an attachment configuration I have setup to go with an email sent during an access request.&nbsp; All the examples I have seen I have to rename the attachment.&nbsp; Currently I am renaming the attachment according to a variable(identityDisplayName).&nbsp; 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);

---

<div class="post-metadata">

**Author:** ![dreddy17](https://avatars.discourse-cdn.com/v4/letter/d/aca169/32.png) [@dreddy17](https://community.sailpoint.com/discuss/u/dreddy17)\
**Post date:** [April 14, 2022, 7:14pm UTC](https://community.sailpoint.com/discuss/t/identityiq-8-2-emailfileattachment-how-to-add-attachment-to-email-w-o-renaming-the-attachment/25851/2 "2022-04-14T19:14:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![deljr1983](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@deljr1983](https://community.sailpoint.com/discuss/u/deljr1983)\
**Post date:** [April 18, 2022, 2:56pm UTC](https://community.sailpoint.com/discuss/t/identityiq-8-2-emailfileattachment-how-to-add-attachment-to-email-w-o-renaming-the-attachment/25851/3 "2022-04-18T14:56:22Z")

</div>

Hi @dreddy17 ,

Thanks for the response.&nbsp; 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”

---

<div class="post-metadata">

**Author:** ![deljr1983](https://avatars.discourse-cdn.com/v4/letter/d/50afbb/32.png) [@deljr1983](https://community.sailpoint.com/discuss/u/deljr1983)\
**Post date:** [April 27, 2022, 12:51am UTC](https://community.sailpoint.com/discuss/t/identityiq-8-2-emailfileattachment-how-to-add-attachment-to-email-w-o-renaming-the-attachment/25851/4 "2022-04-27T00:51:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sabyars](https://avatars.discourse-cdn.com/v4/letter/s/b4bc9f/32.png) [@sabyars](https://community.sailpoint.com/discuss/u/sabyars)\
**Post date:** [October 4, 2023, 8:50pm UTC](https://community.sailpoint.com/discuss/t/identityiq-8-2-emailfileattachment-how-to-add-attachment-to-email-w-o-renaming-the-attachment/25851/5 "2023-10-04T20:50:35Z")

</div>

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