I tried until now to create an object of type MimeMessage using JavaMail api, and after that to obtain its raw representation, but with no success. The only thing that I could obtain is a raw representation of the content of the email, but the header, subject, or recipients were not included. I am interested in any suggestions, any java libraries, that could help me in creating an email object, and after that obtain its raw representation. The raw representation should look something like this:
received: from imta14.emeryville.ca.mail.myisp.net ([nn.nn.30.46])
by alnrmxc19.isp.net (alnrmxc19) with ESMTP
id <20080930215116a19007q9u6e>; Tue, 30 Sep 2008 21:51:16 +0000
X-Originating-IP: [nn.nn.30.46]
Received: from libertatea.go ([nn.nn.161.160])
by IMTA14.mail.isp.net with isp
id M9qy1a00V3TwUto0E9rELB; Tue, 30 Sep 2008 21:51:15 +0000
X-Authority-Analysis: v=1.0 c=1 a=DZlucjOqAY8A:10 a=mnGO974OAAAA:8
a=9MJFf195B83LjESASTQA:9 a=Lm7NQ261g8eJHgoaELoA:7
a=7Narey355jFQWZRww2lj1r9-lCkA:4 a=8COHQAuY8ZYA:10 a=zEVpGHA-kecA:10
a=37WNUvjkh6kA:10
Received: by libertatea.go id hm1nfa0di0sn for <xxx#myisp.net>; Sun,30 Sep 2018 09:36:35
+0300 (envelope-from <Hometown.Quotes_ary#mousemegadot.com>)
Message-ID: <79864795#mousemegadot.com>
Date: Sun, 30 Sep 2018 09:36:35 +0300
From: "Hometown Quotes" <Hometown.Quotes_ary#mousemegadot.com>
To: dummy#myisp.net
Subject: Find Affordable Auto Insurance Today
MIME-Version: 1.0
X-UID: 79864795.modhnrfo.jhhnk.1
Content-Type: multipart/alternative; boundary="0-1411506895-1200484069=:66653"
Content-Transfer-Encoding: 8bit
X-PMFLAGS: 570966272 9 1 PE71PYHD.CNM
X-UC-Weight: [# ] 51
X-CC-Diagnostic: Test 'LazyHTML Tolerant' (51)
--0-1411506895-1200484069=:66653
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
--0-1411506895-1200484069=:66653
Content-transfer-encoding: 8bit
Content-Type: text/html; charset=iso-8859-1; DelSp="Yes"; format="flowed"
What you are looking for is MimeMessag#writeTo which outputs the message as an RFC 822 format stream.
An example of using writeTo to convert a MimeMessage to a String.
MimeMessage mimeMessage;
// mimeMessage get assigned
ByteArrayOutputStream output = new ByteArrayOutputStream();
mimeMessage.writeTo(output);
String rawEmail = output.toString();
Related
Two part question that may or may not be related to each other.
I am running Stackify Prefix v3.0.28 for a Java application on Win10 and it generally seems to work OK: I can see the traces of various actions in our application.
Part 1:
When navigating to any page of our application I get two failed requests to load JS files:
http://127.0.0.1:2/scripts/sfclient.xhr.min.js
http://127.0.0.1:2/scripts/sfclient.perf.prefix.min.js
Both of these requests fail with ERR_CONNECTION_REFUSED. Those script references are not in my JSP page so I assume they are injected by Prefix.
Here is the raw HTML that tries to load the 2 scripts:
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><script src="http://127.0.0.1:2/scripts/sfclient.xhr.min.js"></script>
<script>var SPerfLib = window.SPerfLib || {}; SPerfLib.RequestId = '54fd58d1-7f7e-d3a4-0001-331676a83598'; if(!SPerfLib.isAttached) { document.addEventListener('DOMContentLoaded', function() { var l = document.createElement('script'); l.src = 'http://127.0.0.1:2/scripts/sfclient.perf.prefix.min.js'; document.body.appendChild(l);}); SPerfLib.isAttached = true;}</script>
I have tried looking for configuration options, but found none. I was not sure if the scripts should be server from port 2 or not. The Prefix trace output is from port 2012 and that seems correct.
I tried uninstalling and re-installing Prefix, but with the same results. There does not seem to be any later version of Prefix to try.
How do I get those scripts to load successfully?
Part 2:
On one particular page we have an XHR to retrieve some JSON data. The server is returning data correctly, but it is somehow deleted before it arrives at the browser. The response headers show status 200 but 0 bytes content-length, which then causes some of our JS on the page to fail. If I run the same thing w/o Prefix everything works as expected - status is still 200, but content-length is 37 and JSON payload is visible.
This is the response header for the XHR when Prefix is in play (note content-length: 0)
cache-control: no-cache, must-revalidate
content-language: en-US
content-length: 0
content-type: text/html
date: Mon, 31 Aug 2020 14:19:24 GMT
expires: Thu, 01 Jan 1970 00:00:00 GMT
last-modified: Mon, 31 Aug 2020 14:19:24 GMT
pragma: no-cache
server: WildFly/10
status: 200
x-powered-by: Undertow/1
x-powered-by: JSP/2.3
x-stackifyid: V1|8bbdce1c-a507-bbdc-0001-3378bff33740|
If I remove the Stackify agent from the JVM options and disable the profiler, then the response header looks like this:
cache-control: no-cache, must-revalidate
content-language: en-US
content-length: 37
content-type: text/html;charset=UTF-8
date: Mon, 31 Aug 2020 14:25:12 GMT
expires: Thu, 01 Jan 1970 00:00:00 GMT
last-modified: Mon, 31 Aug 2020 14:25:12 GMT
pragma: no-cache
server: WildFly/10
status: 200
x-powered-by: Undertow/1
I'm appreciative of any suggestions!
These issues you are having with Prefix are known issues with Prefix. We are working on a complete re-write of Prefix (a reason why there has been such a big delay since our last release) and these items are things we are getting fixed in the new Prefix version. We are getting very close to releasing a Beta for Prefix, if you would like to be on the list to give the Prefix beta a try email the Stackify Support Team support#stackify.com
I am a new programmer i am trying to build an app with Json.
If i use this URL doesn't work . http://zsuzsafodraszat.hostzi.com/boltok.json
if i Use this, my app working. https://api.myjson.com/bins/3zm8i
Both Json files exactly the same.
Can you help me what i am doing wrong ? Maybe bad extension or web000 is not a good service for Json ? Can you give me some good free json hosting ? Thanks
Those 2 urls do not have the same content or the same headers. You can see this if run curl commands from the command line:
$ curl -i "http://zsuzsafodraszat.hostzi.com/boltok.json"
HTTP/1.1 200 OK
Date: Wed, 13 Apr 2016 22:52:50 GMT
Server: Apache
Last-Modified: Wed, 13 Apr 2016 16:48:23 GMT
Accept-Ranges: bytes
Content-Length: 1020
Connection: close
Content-Type: application/json
??{"Aldi":"http://catalog.aldi.com/emag/hu_HU/print/Online_katalogus_04_07/Online_katalogus_04_07.pdf",
"Lidl":"http://www.lidl.hu/statics/lidl-hu/ds_doc/HU_HHZ_kw14_2016.pdf",
"Spar":"http://ajanlatok.spar.hu/view/download/?d=1279",
"Penny":"https://view.publitas.com/16538/136265/pdfs/016f82fb5b00bc97b5a8c35f512d89b01cd3e3ce.pdf",
"Coop":"https://view.publitas.com/2556/133497/pdfs/16603d7e9bf30e8a8a4efec7f01d3fa2caf92fe0.pdf",
"Auchan":"http://www.lidl.hu/statics/lidl-hu/ds_doc/HU_HHZ_kw14_2016.pdf"}
$ curl -i "https://api.myjson.com/bins/3zm8i"
HTTP/1.1 200 OK
Server: nginx/1.5.8
Date: Wed, 13 Apr 2016 22:52:56 GMT
Content-Type: application/json
Content-Length: 500
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
{"Aldi":"http://catalog.aldi.com/emag/hu_HU/print/Online_katalogus_04_07/Online_katalogus_04_07.pdf","Lidl":"http://www.lidl.hu/statics/lidl-hu/ds_doc/HU_HHZ_kw14_2016.pdf","Spar":"http://ajanlatok.spar.hu/view/download/?id=1279","Penny":"https://view.publitas.com/16538/136265/pdfs/016f82fb5b00bc97b5a8c35f512d89b01cd3e3ce.pdf","Coop":"https://view.publitas.com/2556/133497/pdfs/16603d7e9bf30e8a8a4efec7f01d3fa2caf92fe0.pdf","Auchan":"http://www.lidl.hu/statics/lidl-hu/ds_doc/HU_HHZ_kw14_2016.pdf"}
As you can see, one of them has a couple of junk bytes at the beginning that my terminal is displaying as question marks. Also the http headers are different. The Content-Lengths are wildly different too. Did you use something other than a plain text editor to create the json payload in the failing example?
Try removing the junk characters and adding these http headers:
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
I am trying to update header data of some Rackspace objects i have uploaded. Example header attribute like: X-Object-Meta-name
But to do that, currently i need to download the whole object and parse the header from the downloaded object. Then do some checking and update if necessary and then upload the object again. But this makes the updating process very slow.
Is there a way to only download the header part of an object and updating it alone? Thanks in advance!
https://github.com/jclouds/jclouds/blob/master/apis/openstack-swift/src/main/java/org/jclouds/openstack/swift/v1/features/ObjectApi.java#L207
If you give it a map with "name"->"the updated header value", it should update the header and automatically add the x-object-meta- prefix.
Is there a way to only download the header part of an object and updating it alone?
I am not a Java developer, but the Cloud Files API is a RESTful one, so I will provide examples using curl. If you are using a library then you may want to edit your question to include which library as many of them abstract these opperations and a better answer can probably be provided in the context of that library.
To download the headers without the object content, perform a HTTP HEAD request.
$ curl -I -XHEAD -H'X-Auth-Token:******' \
> https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_******/container/object
HTTP/1.1 200 OK
Content-Length: 400
Accept-Ranges: bytes
Last-Modified: Tue, 21 Apr 2015 12:06:23 GMT
Etag: 81dc9bdb52d04dc20036dbd8313ed055
X-Timestamp: 1429617982.70468
X-Object-Meta-Foo: Bar
Content-Type: text/html
X-Trans-Id: txd337e4634c98475baf1a4-0055363d42dfw1
Date: Tue, 21 Apr 2015 12:06:26 GMT
To update just the headers on the object, you can then perform a HTTP POST request.
$ curl -i -XPOST -H'X-Auth-Token:******' \
> -H'X-Object-Meta-Foo: Bar' \
> -H'X-Object-Meta-Foo2: Bar2' \
> https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_******/container/object
HTTP/1.1 202 Accepted
Content-Length: 76
Content-Type: text/html; charset=UTF-8
X-Trans-Id: txc262dfe86727440cbfcb1-0055363d5cdfw1
Date: Tue, 21 Apr 2015 12:06:53 GMT
<html><h1>Accepted</h1><p>The request is accepted for processing.</p></html>
Performing another HEAD requeset will show that both the headers are now present.
$ curl -I -XHEAD -H'X-Auth-Token:******' \
> https://storage101.dfw1.clouddrive.com/v1/MossoCloudFS_******/container/object
HTTP/1.1 200 OK
Content-Length: 400
Accept-Ranges: bytes
Last-Modified: Tue, 21 Apr 2015 12:06:53 GMT
Etag: 81dc9bdb52d04dc20036dbd8313ed055
X-Timestamp: 1429618012.98354
X-Object-Meta-Foo: Bar
X-Object-Meta-Foo2: Bar2
Content-Type: text/html
X-Trans-Id: txdd9365b54e8f4d8c8451d-0055363d6adfw1
Date: Tue, 21 Apr 2015 12:07:06 GMT
I'm trying to create a client that can accept a meeting invitation using ActiveSync. I have the meetingresponse over ActiveSync working, but when I send the confirmation email to the organizer and attach the iCalendar formatted reply, it doesn't get parsed out by the server as it should. Instead, it's converted to an attachment and the users attendee status never gets updated.
Here's the MIME email I'm sending:
From: t#xxx.ca
To: Tester Testing <test#xxx.ca>
Message-ID: <i8swl8yv.-4t2#-1387408011.xxx.ca>
Subject: Accepted: Test 11:36 Wed
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="----=_Part_0_1114661696.1429717004439"
------=_Part_0_1114661696.1429717004439
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
these are forced comments
------=_Part_0_1114661696.1429717004439
Content-Type: text/calendar; method=REPLY; charset=utf-8; name=meeting.ics
Content-Transfer-Encoding: quoted-printable
BEGIN:VCALENDAR
METHOD:REPLY
PRODID:XXXEmail
VERSION:2.0
BEGIN:VEVENT
ATTENDEE;PARTSTAT=ACCEPTED:MAILTO:t#xxx.ca
ORGANIZER:MAILTO:test#xxx.ca
DTSTART:20150422T120000
DTEND:20150422T123000
DTSTAMP:20150422T113625
LOCATION;LANGUAGE=en-US:here
UID:3D6D7B89-DE7E-45A1-B916-19DEDB2B1ADC
CLASS:PUBLIC
STATUS:CONFIRMED
TRANSP:OPAQUE
PRIORITY:5
SEQUENCE:0
END:VEVENT
END:VCALENDAR
------=_Part_0_1114661696.1429717004439--
Does anyone see an issue with the iCalendar Reply? Or how the mime is formatted? Or any ideas why this won't work?
EDIT:
As requested, here's an example MIME email that was correctly parsed on the server:
Content-Type: multipart/alternative; boundary="===============0124021817=="
X-Client-ID: 57
X-Mailer: BlackBerry Email (10.3.1.2576)
Message-ID: <20150422140519.5439570.43618.57#xxx.ca>
Date: Wed, 22 Apr 2015 10:05:19 -0400
Subject: Accepted: test at 10:04 Wed
From: <t#xxx.ca>
To: <test#xxx.ca>
MIME-Version: 1.0
--===============0124021817==
Content-Type: text/plain; charset="us-ascii"
Content-Transfer-Encoding: quoted-printable
Commment
--===============0124021817==
Content-Type: text/calendar; charset="utf-8"; name="meeting.ics"; method=REPLY
Content-Transfer-Encoding: quoted-printable
BEGIN:VCALENDAR
PRODID:-//Research In Motion//RIM App//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:REPLY
BEGIN:VTIMEZONE
TZID:America/New_York
BEGIN:STANDARD
DTSTART:20071104T020000
RRULE:FREQ=3DYEARLY;BYDAY=3D1SU;BYMONTH=3D11
TZNAME:EST
TZOFFSETFROM:-0400
TZOFFSETTO:-0500
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:20070311T020000
RRULE:FREQ=3DYEARLY;BYDAY=3D2SU;BYMONTH=3D3
TZNAME:EDT
TZOFFSETFROM:-0500
TZOFFSETTO:-0400
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
ATTENDEE;RSVP=3DTRUE;ROLE=3DREQ-PARTICIPANT;CN=3DTest Test;PARTSTAT=3DACCE=
PTED:mailto:
t#xxx.ca
COMMENT:Commment
CREATED:20150422T140505Z
DTEND;TZID=3DAmerica/New_York:20150422T110000
DTSTAMP:20150422T140518Z
DTSTART;TZID=3DAmerica/New_York:20150422T103000
LOCATION:here
ORGANIZER;CN=3DTesting Tester:mailto:test#xxx.ca
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:test at 10:04 Wed
TRANSP:OPAQUE
UID:A885C120-ABAD-4418-AB24-8B93E57194F0
BEGIN:VALARM
ACTION:DISPLAY
DESCRIPTION:test at 10:04 Wed in 15 minutes.
TRIGGER;RELATED=3DSTART:-PT15M
X-WR-ALARMUID:9b758290-e8f8-11e4-afff-b57e838ad0c3
END:VALARM
END:VEVENT
END:VCALENDAR
--===============0124021817==--
I've tried including the timezone information and it still didn't work. I have another email program that also accepts meeting invites properly, and my iCalendar attachment is basically identical to theirs (they base64 encode the iCalendar attachment which I've also tried with no luck).
When using a different MIME writer (this one came from Android open source project), the vCalendar content I'm sending it interpreted and parsed correctly. I can't see any differences in the MIME format though (besides it being Base64 encoded which I tried and didn't work)...?
Date: Mon, 27 Apr 2015 14:22:43 -0400
Subject: Accepted: test event Monday 2:22
Message-ID: <i907pyoo.17vp#-1387408011.xxx.ca>
From: t#xxx.ca
To: "Tester Testing" <test#xxx.ca>
MIME-Version: 1.0
Content-Type: multipart/alternative; boundary=" _com.android.email_7881218929099440"
----_com.android.email_7881218929099440
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64
----_com.android.email_7881218929099440
Content-Type: text/calendar;
name="meeting.ics"
Content-Transfer-Encoding: base64
QkVHSU46VkNBTEVOREFSDQpNRVRIT0Q6UkVQTFkNClBST0RJRDpYWFhFbWFpbA0KVkVSU0lPTjoyLjANCkJFR0lOOlZFVkVOVA0KVUlEOkFGQzMyNURELTk1MjYtNENFRS05MTlBLUI4RkIxQzU1RTBCQw0KQVRURU5ERUU7UEFSVFNUQVQ9QUNDRVBURUQ6TUFJTFRPOnRAeHh4LmNhDQpPUkdBTklaRVI6TUFJTFRPOnRlc3RAeHh4LmNhDQpEVFNUQVJUOjIwMTUwNDI3VDE0MzAwMA0KRFRFTkQ6MjAxNTA0MjdUMTUwMDAwDQpEVFNUQU1QOjIwMTUwNDI3VDE0MjIzMQ0KTE9DQVRJT047TEFOR1VBR0U9ZW4tVVM6aGVyZQ0KQ0xBU1M6UFVCTElDDQpTVEFUVVM6Q09ORklSTUVEDQpUUkFOU1A6T1BBUVVFDQpQUklPUklUWTo1DQpTRVFVRU5DRTowDQpFTkQ6VkVWRU5UDQpFTkQ6VkNBTEVOREFS
----_com.android.email_7881218929099440--
Try using multipart/mixed instead of multipart/alternative.
The FROM: address in my emails sent from java don't appear correctly. This is not running in an application server but from a main() call:
// Get system properties
final Properties properties = System.getProperties();
// Setup mail server
properties.setProperty("mail.smtp.host", "localhost");
// Get the default Session object.
final Session session = Session.getDefaultInstance(properties);
// Create a default MimeMessage object.
final MimeMessage message = new MimeMessage(session);
// Set From: header field of the header.
message.setFrom(new InternetAddress("support#mydomain.com"));
// Set To: header field of the header.
message.setRecipients(javax.mail.Message.RecipientType.TO, "you#you.com");
// Set Subject: header field
message.setSubject("Your pants are on fire!");
message.setSentDate(new Date());
// Now set the actual message
message.setText("Take me to the bridge. ow!");
// Send message
Transport.send(message);
Here's the raw received email. Two things to note: the linux username under which the java process runs is mungo. The linux servername/hostname is servername. The domain is santamaria.com. These have been changed from their original to protect the guilty.
My question is: why isn't Return-Path support#mydomain.com and how can I make it so? Secondarily, how can I add a friendly name? e.g. Roger Earl <support#mydomain.com>
Delivered-To: you#you.com
Received: by 10.70.125.201 with SMTP id ms9csp51721pdb;
Sat, 22 Nov 2014 07:38:22 -0800 (PST)
X-Received: by 10.140.84.71 with SMTP id k65mr15089869qgd.76.1416670702208;
Sat, 22 Nov 2014 07:38:22 -0800 (PST)
Return-Path: <mungo#servername.santamaria.com>
Received: from servername.santamaria.com (servername.santamaria.com. [201.74.27.72])
by mx.google.com with ESMTPS id z90si10522625qgd.46.2014.11.22.07.38.21
for <you#you.com>
(version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Sat, 22 Nov 2014 07:38:22 -0800 (PST)
Received-SPF: none (google.com: mungo#servername.santamaria.com does not designate permitted sender hosts) client-ip=201.74.27.72;
Authentication-Results: mx.google.com;
spf=none (google.com: mungo#servername.santamaria.com does not designate permitted sender hosts) smtp.mail=mungo#servername.santamaria.com
Received: from servername.santamaria.com (localhost [127.0.0.1])
by servername.santamaria.com (8.14.4/8.14.4) with ESMTP id sAMFcLkq012340
for <you#you.com>; Sat, 22 Nov 2014 15:38:21 GMT
From: RogerEarl <mungo#servername.santamaria.com>
Date: Sat, 22 Nov 2014 15:38:21 +0000 (UTC)
To: you#you.com
Message-ID: <1542856295.1.1416670701712.JavaMail.mungo#servername.santamaria.com>
Subject: Your pants are on fire!
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Take me to the bridge. ow!
UPDATE
The working code looks like this:
properties.setProperty("mail.smtp.from", "support#mydomain.com");
message.setFrom(new InternetAddress("support#mydomain.com", "My Friendly Support Name");
The InternetAddress class includes a constructor that allows you to set a "personal name" along with the email address; read the javadocs.
The Return-Path header is set by the receiving mail server, probably based on the "envelope from" address. Set the mail.smtp.from property to the address you want to use.