Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Notification of email with latest txt or excel attachments are not sending

Omprakash Thamsetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 4, 2015

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.

 

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Omprakash Thamsetty
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 8, 2015
////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

TAGS
AUG Leaders

Atlassian Community Events