Here is an alternative solution very similar to the accepted answer if you're using jQuery and would like to extend its functionality to accomplish this. Just as good as the other answer but thought I'd throw out an alternative solution that I use. So far I haven't had any issues with cross browser usage. I didn't go back and try older versions of IE though, just used the more current version of each browser to test this.
Extending jQuery to include your custom mailer function
$(function () {
$.fn.myMailer = function () {
this.display = function() {
var url = 'mailto:' + this.To +
'?subject=' + encodeURIComponent(this.Subject) +
'&body=' + encodeURIComponent(this.HTMLBody);
window.location = url;
return true;
}
}
});
Example Usage:
var myMailItem = new $.fn.myMailer();
myMailItem.To = '[email protected]';
myMailItem.Subject = 'Your Subject';
myMailItem.HTMLBody = 'Whatever you want your E-Mail to say';
myMailItem.display(0);
Furthermore if you'd like to add CC or BCC recipients then follow the structure above to add them to the mailto query string as well.
I also tried to get an attachment in an Outlook E-Mail on the clients computer
$(function () {
$.fn.myMailer = function () {
this.display = function() {
var url = 'mailto:' + this.To + '?content-type=' +
encodeURIComponent('multipart/form-data') +
'&subject=' + encodeURIComponent(this.Subject) +
'&body=' + encodeURIComponent(this.HTMLBody) +
'&attachment=' + encodeURIComponent(this.Attachment);
window.location = url;
return true;
}
}
});
I failed with this attempt. I'm not sure this is possible solely from the use of client side code. I could be wrong. This could also pose a security threat I'd think if it is possible.
I'd say the best bet here would be to use client scripting to invoke some server side code however you prefer to go about that and have the server send out the E-Mail if applicable.
I however needed the attachment added to an Outlook E-Mail which would pop-up on the clients computer so I'm still working out the final details of how to handle adding attachments for my situation. Using .NET I think there should be some way to handle this I just haven't had time to implement the server side handler to accomplish it yet. If someone else is trying to accomplish the same sort of thing using .NET here is a good link to get started with Outlook 2013 MailItem properties.