Open Outlook Email with BCC's on Client from ASP.NET
I have tried several ways to open an outlook email on the client in ASP.NET and only found one okay solution - but it requires IE and Active-X enabled for the site.
Try 1: Use mailto. Fails if message body is too large. No good.
Try 2: Use Outlook API to generate email file and stream to client - this only works if outlook is on the server. No good.
Try 3: Write a plain text .eml file and stream to client - this only works if client is using a version of outlook that can open .eml files, such as 2010 or Express. Also it does not support BCCs. No good.
Try 4: Use .Net MailMessage to save an email to the 'drop folder', manually mark it as unsent, and stream to client. Outlook couldn't handle weird x-headers generated, BCC failed to persist. No good.
Uses the ScriptProvider design pattern to render compile-time JS:
(this overload assumes body should be blank, but see other example below for how to specify body)
public ScriptProvider OpenOutlookEmail(List<string> bcc_addresses, string subject, string attachmentUrl)
// create our emailer
this.SetVariable("customEmail", "new ActiveXObject('Outlook.Application').CreateItem(0)");
//add some recipients; type is 1 (normal), 2 (cc) or 3 (bcc)
if (bcc_addresses != null)
foreach (string bcc in bcc_addresses)
// set subject
// attachment support
//1=Add by value so outlook downloads the file from the url
// error handling
this.AlertString("Outlook Access requires Internet Explorer and ActiveX enabled. Please put this site in your trusted sites and enable 'Initialize and script ActiveX controls not marked as safe for scripting' to use this feature.");
If you would rather have plain JS, start from this and edit as needed.
//get outlook and create new email
var outlook = new ActiveXObject('Outlook.Application');
var email = outlook.CreateItem(0);
//add some recipients
email.Recipients.Add('email@example.com').Type = 1; //1=To
email.Recipients.Add('firstname.lastname@example.org').Type = 2; //2=CC
email.Recipients.Add('email@example.com').Type = 3; //2=CC
//subject and attachments
email.Subject = '';
//email.Attachments.Add('URL_TO_FILE', 1); //1=Add by value so outlook downloads the file from the url
// display the email (this will make the signature load so it can be extracted)
//use a regular expression to extract the html before and after the signature
var signatureExtractionExpression = new RegExp('/[^~]*(<BODY[^>]*>)([^~]*</BODY>)[^~]*/', 'i');
var beforeSignature = RegExp.$1;
var signature = RegExp.$2;
//set the html body of the email
email.HTMLBody = beforeSignature + '<h1>Our Custom Body</h1>' + signature;
alert("Outlook Access requires Internet Explorer and ActiveX enabled. Please put this site in your trusted sites and enable 'Initialize and script ActiveX controls not marked as safe for scripting' to use this feature.");
Created By: amos 3/23/2015 2:20:32 PM
Updated: 3/23/2015 2:23:34 PM