JoseMRodriguez1 / DragAndDropOutlookJava

Drag and Drop Outlook emails or any other files to JList
1 stars 0 forks source link

Outlook language shouldn't matter #1

Open Geodomus opened 6 years ago

Geodomus commented 6 years ago

In DnDList.java, Line 109 (the IF), you're currently only checking for "Subject", which works fine with english outlooks, but just gave me massive trouble finding out why it didn't work in our company (we're having a german outlook in use here).

It would be great if you could somehow make it language independent.

JoseMRodriguez1 commented 6 years ago

Hi Geodomus, do you need the Drag and Drop functionality?

I stopped using the Drag and Drop approach and started using the microsoft.exchange.webservices API. The microsoft library allows you to connect directly into the MS Exchange Server and allows you to control what you want to do with each email.

Geodomus commented 6 years ago

It's basically a requirement from the guys using it, so yes, unfortunately, i need the D&D functionality.

JoseMRodriguez1 commented 6 years ago

Ok, I'll try to update the code over the weekend.

I added some sample code below for the microsoft library. You can use this code to do some automation with your emails.

ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2);

ExchangeCredentials credentials = new WebCredentials("___Email_Address___", "___Password___");
service.setCredentials(credentials);
service.autodiscoverUrl("___Email_Address___");

FolderId folderToAccess = new FolderId(WellKnownFolderName.Inbox, new Mailbox("___Email_Address___"));
Folder inboxFLDR = Folder.bind(service, folderToAccess);

ItemView view = new ItemView(Integer.MAX_VALUE);
view.getOrderBy().add(ItemSchema.DateTimeReceived, SortDirection.Descending);

// Filter to emails with attachments only
SearchFilter.IsEqualTo hasAttachmentFilter = new SearchFilter.IsEqualTo(ItemSchema.HasAttachments, true);

FindItemsResults<Item> results = service.findItems(inboxFLDR.getId(), hasAttachmentFilter, view);

if(results.getTotalCount() > 0)
{
    service.loadPropertiesForItems(results, new PropertySet(EmailMessageSchema.HasAttachments));

    for(Item item : results)
    {
        Item itm = Item.bind(service, item.getId(), new PropertySet(ItemSchema.Attachments));

        itm.load();

        EmailMessage emailMessage = EmailMessage.bind(service, itm.getId(), new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.HasAttachments));

        if(emailMessage.getAttachments().getItems().size() > 0 && emailMessage.getSubject() != null)
        {
            //Write what you want to do with email
        }
    }
}

//.....
service.close();