Reading Email Attachments Using JavaMail - Reading 'winmail.dat' Rather Than Actual Attachment










0















I am attempting to build a client that uses the javax.mail API to read email messages, including attachments. My initial thought was to use the Tika library. When that produced an unexpected result (please refer to code and details below), I tried using a variation of the code presented in this question.



My function for reading emails:



 // Reference: https://www.tutorialspoint.com/javamail_api/javamail_api_checking_emails.htm
public class CheckingMails {

public static void check(String host, String storeType, String user, String password)
try

// create properties field
Properties properties = new Properties();

properties.put("mail.pop3.host", host);
properties.put("mail.pop3.port", "110");
Session emailSession = Session.getInstance(properties);
Store store = emailSession.getStore("pop3");
store.connect(host, user, password);
Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_WRITE);

// retrieve the messages from the folder in an array and print it
Message messages = emailFolder.getMessages();

System.out.println("messages.length---" + messages.length);

for (int i = 0, n = messages.length; i < n; i++)
Message message = messages[i];

Object content = message.getContent();
if (content instanceof java.lang.String)
System.out.println((String) content);
else if (content instanceof Multipart)
Multipart mp = (Multipart) content;

for (int j = 0; j < mp.getCount(); j++) disposition.equals(Part.INLINE)))
// Check if plain
MimeBodyPart mbp = (MimeBodyPart) part;
if (mbp.isMimeType("text/plain"))
System.out.println("Mime type is plain");
System.out.println((String) mbp.getContent());
else
System.out.println("Save file " + part.getFileName());






System.out.println("Tika results " + parseMsg(message));



// close the store and folder objects
emailFolder.close(false);
store.close();

catch (MessagingException e)
e.printStackTrace();
catch (Exception e)
e.printStackTrace();




When I test the program by sending a test message with a simple CSV as an attachment, the Tika parser outputs the following (truncated for brevity):



 ------=_NextPart_000_0028_01D47C16.81FB45C0
Content-Type: application/ms-tnef;
name="winmail.dat"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="winmail.dat"

eJ8+IhUSAQaQCAAEAAAAAAABAAEAAQeQBgAIAAAA5AQAAAAAAADoAAEIgAcAGAAAAElQTS5NaWNy
b3NvZnQgTWFpbC5Ob3RlADEIAQOQBgCgDQAANgAAAAsAAgABAAAAAwAmAAAAAAALACkAAAAAAB4A
cAABAAAABQAAAFRlc3QAAAAAAgFxAAEAAAAWAAAAAdR8SMswwghurPF+SpeO8uRrTzrhCgAACwAB
DgAAAAACAQoOAQAAABg.....

------=_NextPart_000_0028_01D47C16.81FB45C0--


The other portion of the code (that checks for the message's disposition), outputs something similar to the following:



 messages.length---1
Mime type is plain



Email Boday



Save file winmail.dat


Why is the application reading/recognizing winmail.dat and not the attachment that was actually sent with the message (a CSV file)?



Thanks for any help.










share|improve this question






















  • If you're using Outlook to send the message, you need to configure it to send standard MIME messages and not the old Windows style winmail.dat attachments.

    – Bill Shannon
    Nov 14 '18 at 22:34











  • Use HMEF from Apache POI and you can decode the winmail.dat file. (That's what Apache Tika uses internally to handle them!)

    – Gagravarr
    Nov 15 '18 at 7:57
















0















I am attempting to build a client that uses the javax.mail API to read email messages, including attachments. My initial thought was to use the Tika library. When that produced an unexpected result (please refer to code and details below), I tried using a variation of the code presented in this question.



My function for reading emails:



 // Reference: https://www.tutorialspoint.com/javamail_api/javamail_api_checking_emails.htm
public class CheckingMails {

public static void check(String host, String storeType, String user, String password)
try

// create properties field
Properties properties = new Properties();

properties.put("mail.pop3.host", host);
properties.put("mail.pop3.port", "110");
Session emailSession = Session.getInstance(properties);
Store store = emailSession.getStore("pop3");
store.connect(host, user, password);
Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_WRITE);

// retrieve the messages from the folder in an array and print it
Message messages = emailFolder.getMessages();

System.out.println("messages.length---" + messages.length);

for (int i = 0, n = messages.length; i < n; i++)
Message message = messages[i];

Object content = message.getContent();
if (content instanceof java.lang.String)
System.out.println((String) content);
else if (content instanceof Multipart)
Multipart mp = (Multipart) content;

for (int j = 0; j < mp.getCount(); j++) disposition.equals(Part.INLINE)))
// Check if plain
MimeBodyPart mbp = (MimeBodyPart) part;
if (mbp.isMimeType("text/plain"))
System.out.println("Mime type is plain");
System.out.println((String) mbp.getContent());
else
System.out.println("Save file " + part.getFileName());






System.out.println("Tika results " + parseMsg(message));



// close the store and folder objects
emailFolder.close(false);
store.close();

catch (MessagingException e)
e.printStackTrace();
catch (Exception e)
e.printStackTrace();




When I test the program by sending a test message with a simple CSV as an attachment, the Tika parser outputs the following (truncated for brevity):



 ------=_NextPart_000_0028_01D47C16.81FB45C0
Content-Type: application/ms-tnef;
name="winmail.dat"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="winmail.dat"

eJ8+IhUSAQaQCAAEAAAAAAABAAEAAQeQBgAIAAAA5AQAAAAAAADoAAEIgAcAGAAAAElQTS5NaWNy
b3NvZnQgTWFpbC5Ob3RlADEIAQOQBgCgDQAANgAAAAsAAgABAAAAAwAmAAAAAAALACkAAAAAAB4A
cAABAAAABQAAAFRlc3QAAAAAAgFxAAEAAAAWAAAAAdR8SMswwghurPF+SpeO8uRrTzrhCgAACwAB
DgAAAAACAQoOAQAAABg.....

------=_NextPart_000_0028_01D47C16.81FB45C0--


The other portion of the code (that checks for the message's disposition), outputs something similar to the following:



 messages.length---1
Mime type is plain



Email Boday



Save file winmail.dat


Why is the application reading/recognizing winmail.dat and not the attachment that was actually sent with the message (a CSV file)?



Thanks for any help.










share|improve this question






















  • If you're using Outlook to send the message, you need to configure it to send standard MIME messages and not the old Windows style winmail.dat attachments.

    – Bill Shannon
    Nov 14 '18 at 22:34











  • Use HMEF from Apache POI and you can decode the winmail.dat file. (That's what Apache Tika uses internally to handle them!)

    – Gagravarr
    Nov 15 '18 at 7:57














0












0








0








I am attempting to build a client that uses the javax.mail API to read email messages, including attachments. My initial thought was to use the Tika library. When that produced an unexpected result (please refer to code and details below), I tried using a variation of the code presented in this question.



My function for reading emails:



 // Reference: https://www.tutorialspoint.com/javamail_api/javamail_api_checking_emails.htm
public class CheckingMails {

public static void check(String host, String storeType, String user, String password)
try

// create properties field
Properties properties = new Properties();

properties.put("mail.pop3.host", host);
properties.put("mail.pop3.port", "110");
Session emailSession = Session.getInstance(properties);
Store store = emailSession.getStore("pop3");
store.connect(host, user, password);
Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_WRITE);

// retrieve the messages from the folder in an array and print it
Message messages = emailFolder.getMessages();

System.out.println("messages.length---" + messages.length);

for (int i = 0, n = messages.length; i < n; i++)
Message message = messages[i];

Object content = message.getContent();
if (content instanceof java.lang.String)
System.out.println((String) content);
else if (content instanceof Multipart)
Multipart mp = (Multipart) content;

for (int j = 0; j < mp.getCount(); j++) disposition.equals(Part.INLINE)))
// Check if plain
MimeBodyPart mbp = (MimeBodyPart) part;
if (mbp.isMimeType("text/plain"))
System.out.println("Mime type is plain");
System.out.println((String) mbp.getContent());
else
System.out.println("Save file " + part.getFileName());






System.out.println("Tika results " + parseMsg(message));



// close the store and folder objects
emailFolder.close(false);
store.close();

catch (MessagingException e)
e.printStackTrace();
catch (Exception e)
e.printStackTrace();




When I test the program by sending a test message with a simple CSV as an attachment, the Tika parser outputs the following (truncated for brevity):



 ------=_NextPart_000_0028_01D47C16.81FB45C0
Content-Type: application/ms-tnef;
name="winmail.dat"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="winmail.dat"

eJ8+IhUSAQaQCAAEAAAAAAABAAEAAQeQBgAIAAAA5AQAAAAAAADoAAEIgAcAGAAAAElQTS5NaWNy
b3NvZnQgTWFpbC5Ob3RlADEIAQOQBgCgDQAANgAAAAsAAgABAAAAAwAmAAAAAAALACkAAAAAAB4A
cAABAAAABQAAAFRlc3QAAAAAAgFxAAEAAAAWAAAAAdR8SMswwghurPF+SpeO8uRrTzrhCgAACwAB
DgAAAAACAQoOAQAAABg.....

------=_NextPart_000_0028_01D47C16.81FB45C0--


The other portion of the code (that checks for the message's disposition), outputs something similar to the following:



 messages.length---1
Mime type is plain



Email Boday



Save file winmail.dat


Why is the application reading/recognizing winmail.dat and not the attachment that was actually sent with the message (a CSV file)?



Thanks for any help.










share|improve this question














I am attempting to build a client that uses the javax.mail API to read email messages, including attachments. My initial thought was to use the Tika library. When that produced an unexpected result (please refer to code and details below), I tried using a variation of the code presented in this question.



My function for reading emails:



 // Reference: https://www.tutorialspoint.com/javamail_api/javamail_api_checking_emails.htm
public class CheckingMails {

public static void check(String host, String storeType, String user, String password)
try

// create properties field
Properties properties = new Properties();

properties.put("mail.pop3.host", host);
properties.put("mail.pop3.port", "110");
Session emailSession = Session.getInstance(properties);
Store store = emailSession.getStore("pop3");
store.connect(host, user, password);
Folder emailFolder = store.getFolder("INBOX");
emailFolder.open(Folder.READ_WRITE);

// retrieve the messages from the folder in an array and print it
Message messages = emailFolder.getMessages();

System.out.println("messages.length---" + messages.length);

for (int i = 0, n = messages.length; i < n; i++)
Message message = messages[i];

Object content = message.getContent();
if (content instanceof java.lang.String)
System.out.println((String) content);
else if (content instanceof Multipart)
Multipart mp = (Multipart) content;

for (int j = 0; j < mp.getCount(); j++) disposition.equals(Part.INLINE)))
// Check if plain
MimeBodyPart mbp = (MimeBodyPart) part;
if (mbp.isMimeType("text/plain"))
System.out.println("Mime type is plain");
System.out.println((String) mbp.getContent());
else
System.out.println("Save file " + part.getFileName());






System.out.println("Tika results " + parseMsg(message));



// close the store and folder objects
emailFolder.close(false);
store.close();

catch (MessagingException e)
e.printStackTrace();
catch (Exception e)
e.printStackTrace();




When I test the program by sending a test message with a simple CSV as an attachment, the Tika parser outputs the following (truncated for brevity):



 ------=_NextPart_000_0028_01D47C16.81FB45C0
Content-Type: application/ms-tnef;
name="winmail.dat"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="winmail.dat"

eJ8+IhUSAQaQCAAEAAAAAAABAAEAAQeQBgAIAAAA5AQAAAAAAADoAAEIgAcAGAAAAElQTS5NaWNy
b3NvZnQgTWFpbC5Ob3RlADEIAQOQBgCgDQAANgAAAAsAAgABAAAAAwAmAAAAAAALACkAAAAAAB4A
cAABAAAABQAAAFRlc3QAAAAAAgFxAAEAAAAWAAAAAdR8SMswwghurPF+SpeO8uRrTzrhCgAACwAB
DgAAAAACAQoOAQAAABg.....

------=_NextPart_000_0028_01D47C16.81FB45C0--


The other portion of the code (that checks for the message's disposition), outputs something similar to the following:



 messages.length---1
Mime type is plain



Email Boday



Save file winmail.dat


Why is the application reading/recognizing winmail.dat and not the attachment that was actually sent with the message (a CSV file)?



Thanks for any help.







java javamail apache-tika






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 14 '18 at 18:45









KellyMarchewaKellyMarchewa

7661133




7661133












  • If you're using Outlook to send the message, you need to configure it to send standard MIME messages and not the old Windows style winmail.dat attachments.

    – Bill Shannon
    Nov 14 '18 at 22:34











  • Use HMEF from Apache POI and you can decode the winmail.dat file. (That's what Apache Tika uses internally to handle them!)

    – Gagravarr
    Nov 15 '18 at 7:57


















  • If you're using Outlook to send the message, you need to configure it to send standard MIME messages and not the old Windows style winmail.dat attachments.

    – Bill Shannon
    Nov 14 '18 at 22:34











  • Use HMEF from Apache POI and you can decode the winmail.dat file. (That's what Apache Tika uses internally to handle them!)

    – Gagravarr
    Nov 15 '18 at 7:57

















If you're using Outlook to send the message, you need to configure it to send standard MIME messages and not the old Windows style winmail.dat attachments.

– Bill Shannon
Nov 14 '18 at 22:34





If you're using Outlook to send the message, you need to configure it to send standard MIME messages and not the old Windows style winmail.dat attachments.

– Bill Shannon
Nov 14 '18 at 22:34













Use HMEF from Apache POI and you can decode the winmail.dat file. (That's what Apache Tika uses internally to handle them!)

– Gagravarr
Nov 15 '18 at 7:57






Use HMEF from Apache POI and you can decode the winmail.dat file. (That's what Apache Tika uses internally to handle them!)

– Gagravarr
Nov 15 '18 at 7:57













0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306866%2freading-email-attachments-using-javamail-reading-winmail-dat-rather-than-act%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53306866%2freading-email-attachments-using-javamail-reading-winmail-dat-rather-than-act%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

政党

天津地下鉄3号線