I have written the email notification with attachment. It is working fine when same kind of file extension exist. For example: If I have file1.txt , file2.txt and file3.txt attachment for issue then email notification picking the latest file and sending as expected. If I add file4.exls to the same issue then email notification sending with file3.txt file only not the file4.exls because file format is different.
Same way If I add file1.xls, file2.xls then email notification sending with last attached file. But If I add file3.txt file then email sending with file2.xls only.
Here is my code for sending the email notification. Please advise me what I need to add to send email notification to send last attached file for issue? something I am missing.
NOTE: I configured the email notification for workflow - post function
////Checking for attachment. Multipart multipart = new MimeMultipart("mixed"); BodyPart attachBody = new MimeBodyPart(); List<Attachment> attachments = attachmentManager.getAttachments(issue); if(!attachments.isEmpty()) { for (Attachment attachment : attachments) { filepath = AttachmentUtils.getAttachmentFile(attachment); attachFileName = attachment.getFilename(); } FileDataSource source = new FileDataSource(filepath); attachBody.setDataHandler(new DataHandler(source)); attachBody.setFileName(attachFileName); multipart.addBodyPart(attachBody); email.setMultipart(multipart); }
Any help much appreciate.
Community moderators have prevented the ability to post new answers.
////Checking for attachment. Multipart multipart = new MimeMultipart("mixed"); BodyPart attachBody = new MimeBodyPart(); List<Attachment> attachments = attachmentManager.getAttachments(issue); NumOfAttachedfiles = attachments.size(); if(!attachments.isEmpty()) { def fileCreatedDate, fileCreatedDateFinal; Attachment attachmentFinal; for (int i=0; i< NumOfAttachedfiles; i++) { Attachment attachment = attachments[i]; fileCreatedDate = attachment.getCreated(); if(i==0){ fileCreatedDateFinal = fileCreatedDate; attachedFile = AttachmentUtils.getAttachmentFile(attachment); attachedFileName = attachment.getFilename(); }else{ if(fileCreatedDate.after(fileCreatedDateFinal)){ fileCreatedDateFinal = fileCreatedDate; attachedFile = AttachmentUtils.getAttachmentFile(attachment); attachedFileName = attachment.getFilename(); } }//else } //for FileDataSource source = new FileDataSource(attachedFile); attachBody.setDataHandler(new DataHandler(source)); attachBody.setFileName(attachedFileName); multipart.addBodyPart(attachBody); email.setMultipart(multipart);
The above code worked for me to get the latest attached file and send email notification.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.