I'm trying to write a short test to test some email problems I've been having.
My test mail (removed some personal info):
Received: from <address> (<ip>) by
<address> (<ip>) with Microsoft SMTP
Server (TLS) id <ip>; <time>
Received: from <address> (<ip>) by
<address> (<ip>) with mapi id
<ip>; <time>
From: <name> <<mail>>
To: <name> <<mail>>
Subject: =?iso-8859-1?Q?<subject>?=
Thread-Topic: =?iso-8859-1?Q?<subject>?=
Thread-Index: <index>==
Date: <time>
Message-ID: <<message-id>>
References: <<references-id>>
<<references-id>>
<<references-id>>
In-Reply-To: <<references-id>>
Accept-Language: sv-SE, en-US
Content-Language: sv-SE
X-MS-Exchange-Organization-AuthAs: Internal
X-MS-Exchange-Organization-AuthMechanism: 04
X-MS-Exchange-Organization-AuthSource: <<address>>
X-MS-Has-Attach:
X-MS-Exchange-Organization-SCL: -1
X-MS-Exchange-Inbox-Rules-Loop: <address>
X-MS-TNEF-Correlator:
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
MIME-Version: 1.0
<html>
<head>
<meta http-equiv=3D"Content-Type" content=3D"text/html; charset=3Diso-8859-=1">
</head>
<body>
text, nothing special a bit of css and some html code
</body>
</html>
My test code:
Session s = Session.getDefaultInstance(new Properties());
mime = EmailTest.class.getResourceAsStream("/mailtests/parsehtmlmail1.mime");
MimeMessage msg = new MimeMessage(s, mime);
InputStream is = msg.getRawInputStream();
System.out.println(is.read());
if(msg.getContentType().toLowerCase().startsWith("text/html")){
if(msg.isMimeType("text/html")){
if(msg.getContent() instanceof String) {
System.out.println("Here");
System.out.println(msg.getContent().toString());
InputStream is2 = msg.getInputStream();
System.out.println(is2.read());
}
}
}
Result:
-1
Here
-1
So my problem is, no matter what I try I keep ending up with an empty content string or empty inputstreams.
So what am I doing this wrong? Or is it something I don't understand? I was under the impression that I should be able to use the inputstream since the mimetype is text/html.
Could the error have something to do with my test file? I only copied the mail and pasted it into a file I named "parsehtmlmail1.mime". If so, how come I can use getContentType() etc?