0

Ews I am doing mail reading and I want to return mail attachments. I want the frontend to list the attachments and I want them to be downloaded when clicked. So what should I return?

public List<MailResponseDto> readEmailItem(ItemId itemId) {
  MailResponseDto messageData = new MailResponseDto();
List<String> downloadFileNames = new ArrayList<>();
List<MailResponseDto> mailResponseDtos = new ArrayList<>();
try {
    Item itm = Item.bind(service, itemId, PropertySet.FirstClassProperties);
    EmailMessage emailMessage = EmailMessage.bind(service, itm.getId());
    messageData.setEmailItemId(emailMessage.getId().toString());
    messageData.setSubject(emailMessage.getSubject());
    messageData.setFromAddress(emailMessage.getFrom().getAddress());
    messageData.setSenderName(emailMessage.getSender().getName().toString());
    Date dateTimeCreated = emailMessage.getDateTimeCreated();
    messageData.setSendDate(dateTimeCreated.toString());
    Date dateTimeRecieved = emailMessage.getDateTimeReceived();
    messageData.setRecievedDate(dateTimeRecieved.toString());
    messageData.setSize(emailMessage.getSize());
    messageData.setEmailBody(emailMessage.getBody().toString());
    mailResponseDtos.add(messageData);
    if (emailMessage.getHasAttachments()) {
        AttachmentCollection attachmentsCol = itm.getAttachments();
        for (int i = 0; i < attachmentsCol.getCount(); i++) {
            FileAttachment attachment = (FileAttachment) 
       attachmentsCol.getPropertyAtIndex(i);
            attachment.load(mailProperty.getSaveDirectory() + attachment.getName());
            downloadFileNames.add(attachment.getName());
        }
    }
} catch (Exception e) {
    e.printStackTrace();
}
return mailResponseDtos;
}

and MailResponseDto;

MailResponseDto
public class MailResponseDto {
private String emailItemId;
private String subject;
private String fromAddress;
private String senderName;
private String sendDate;
private String recievedDate;
private int size;
private String emailBody;
private List<File> files;

}

Bill Shannon
  • 29,579
  • 6
  • 38
  • 40
  • So the code you posted appears to do what you are asking so you may want to clarify your question. Or if the code you posted doesn't work explain why it doesn't work and what error you receive. – Glen Scales Jun 05 '18 at 23:24
  • Hi, I am reading the mails and Attachments I want set attachment files my DTo Class List and return my Dto How can set my Attachments My Dto ? – ramcolinho Jun 06 '18 at 12:18

0 Answers0