My objective is to send a request to the server, and with the response (in EML format) open Outlook and Thunderbird, from where a user can edit the email text and send it out.
I'm using a Java servlet to generate the response (I think this shouldn't matter) with the following headers:
Content-Type: message/rfc822
Content-Disposition: attachment; filename="email.eml"
The problem is that the browser downloads the file instead of opening it directly in the browser. I tried with
Content-Disposition: inline; filename="email.eml"
but have the same problem. I tested with IE10 and Chrome 38, both have similar behavior.
If the user clicks on the downloaded file the email app opens correctly and they can send the email, but the downloaded file remains on disk generating a lot of garbage.
Any thoughts?
The only alternative solution I can think of is using the mailto protocol.
https://tools.ietf.org/html/rfc2368
Mailto allows you to specify the usual email fields such as body, subject, send to address, etc.
To automatically have the email open use this bit of JavaScript:
// Setting these here for the sake or readability.
var toaddress = "email@address.com";
var subject = "Subject Line";
var body = "Message contents here.\n\nNewlines work too";
window.location = "mailto:?to=" + encodeURIComponent(toaddress)
+ "&subject=" + encodeURIComponent(subject) + "&body="
+ encodeURIComponent(body);
Using this you could modify your servlet to return the subject, body, and to address with an AJAX call and upon returning execute the snippet above.
Take this with a grain of salt however, as any specifications beyond what's listed in the standard are entirely up to the email clients being used (e.g. does the body HTML?).