EWS读取并带有附件的returnMail

时间:2018-06-05 15:36:35

标签: exchange-server exchangewebservices email-attachments ewsjavaapi

Ews我正在阅读邮件,我想要回复邮件附件。我希望前端列出附件,我希望在单击时下载它们。那我该怎么回事呢?

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;
}

和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;

}

0 个答案:

没有答案