Read access request attachment and append to the email

Which IIQ version are you inquiring about?

Version 8.X

Share all details related to your problem, including any error messages you may have received.

Has anyone come across a requirement to read the file attachments added in the access request and then append the file attachment into the approval email?

I know the attachment in the request are represented in the AttachmentDTO tags. I m kind of unsure if the attachment can be directly read and passed as an argument to the email template or needs to be reconstructed by reading the file name and the byte array of its content.

I have got a sample code from the community as below:

List attachment=accRequest.getArgument("attachments");
AttachmentDTO attDTO = attachment.get(0); 
Attachment attch=context.getObjectByName(Attachment.class, attDTO.getName());

Any help will be appreciated.

Hi @rabshrestha,

You can use below template to send attachement. Let me know if you face any issue.

EmailTemplate template=context.getObjectByName(EmailTemplate.class,"SampleTemplate");
		IdentityRequest request=context.getObjectById(IdentityRequest.class,"request id");
		
		List itemList= request.getItems();
		List attachList=itemList.get(0).getAttachments();
		
		
		EmailFileAttachment fileAttach=new EmailFileAttachment();
		fileAttach.setData(attachList.get(0).getContent());
		EmailOptions opt=new EmailOptions();
		opt.setTo("[email protected]");
		opt.setVariable("identityName","userName");
		opt.addAttachment(fileAttach);
		
		context.sendEmailNotification(template, opt);

Thanks

2 Likes

Thank you Ashutosh.

I did a few tweaks into the code above:

	EmailTemplate template=context.getObjectByName(EmailTemplate.class,"Test-EmailTemplate-Rabindra");
	IdentityRequest request=context.getObjectByName(IdentityRequest.class,"0000023456");
	List itemList= request.getItems();
	List attachList=itemList.get(0).getAttachments();
	String fileName = attachList.get(0).getName();
	byte[] bytesArray = attachList.get(0).getContent();

	EmailFileAttachment file = new EmailFileAttachment(fileName, bytesArray);

	EmailOptions opt=new EmailOptions();
	opt.setAttachments(Collections.singletonList(file));
	opt.setTo("[email protected]");
	opt.setVariable("identityName","johndoe");

	context.sendEmailNotification(template, opt);

With the change I am able to read the attachment and append it into the email. Only one issue I have is that when I open and check the content of the file, it seems kind of encoded values as below:

2:ACP:3Nwo68lnDwfBVxjSVdSuraXvW2KiGI7aqGiZsHuCfZ86hw0+oRENnWgVLU4u9A9pXDS/fbhuf4Hd
uEPLQcxX1w==

is there any decoding that has to be performed?

Regards,
Rabindra

Just for the testing have you validated the data being returned from the above line is have some proper details.
Also, which file type you are attaching at present and then reading?

Thanks

Yep the statement above return the attachment information as below:
image

The testAttachment.txt file is a sample file that includes dummy sentences as below:
image

When i open the attachment from the email, the sample file content seems encoded as follows:
2:ACP:3Nwo68lnDwfBVxjSVdSuraXvW2KiGI7aqGiZsHuCfZ86hw0+oRENnWgVLU4u9A9pXDS/fbhuf4Hd
uEPLQcxX1w==

Regards,
Rabindra

In case of PNG attachment, the content can not be viewed:

PNG ATTACHMENT
image

The content is not viewable:

this seems to be encrypted using IIQ key , do you want to see if you can use decrpyt method to see if this can decrpyted to pain text .

1 Like

Ty Vishal… i checked with the decrypt method of the following encrypted string:
2:ACP:3Nwo68lnDwfBVxjSVdSuraXvW2KiGI7aqGiZsHuCfZ86hw0+oRENnWgVLU4u9A9pXDS/fbhuf4Hd
uEPLQcxX1w==

but the return is not the correct content present in the file:

image

not sure if you have looked into this doc
IdentityIQ 8.0: File attachments in access requests - Compass

I have been through the doc and the attachment settings are all good on our implementation.

https://community.sailpoint.com/t5/IdentityIQ-Forum/Read-Attachment-Data-From-an-Access-Request/m-p/182004

1 Like

https://community.sailpoint.com/t5/IdentityIQ-Forum/IdentityIQ-8-2-EmailFileAttachment-How-to-add-attachment-to/m-p/213602

1 Like

I did refer this post early. Second links seem helpful… Ty Vishal

This post has the midas touch :slight_smile: . The decrypt method under AttachmentService class was what I was looking for. Thank you Vishal :pray:

1 Like

Great to know that it worked .
Happy Learning !

1 Like

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.