This can be achieved using JavaScript in IE if the site is a Trusted Site and ActiveX objects are enabled. I have had this script work as far back as IE6 and tested up to IE10 I am unsure about its support in IE11.
An important point about the script below is that you must call Display
on the email before trying to extract the signature from it or trying to set its HTMLBody
otherwise you will lose the signature information.
try {
//get outlook and create new email
var outlook = new ActiveXObject('Outlook.Application');
var email = outlook.CreateItem(0);
//add some recipients
email.Recipients.Add('user1@company.com').Type = 1; //1=To
email.Recipients.Add('user2@company.com').Type = 2; //2=CC
//subject and attachments
email.Subject = 'A 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)
email.Display();
//use a regular expression to extract the html before and after the signature
var signatureExtractionExpression = new RegExp('/[^~]*(<BODY[^>]*>)([^~]*</BODY>)[^~]*/', 'i');
signatureExtractionExpression.exec(email.HTMLBody);
var beforeSignature = RegExp.$1;
var signature = RegExp.$2;
//set the html body of the email
email.HTMLBody = beforeSignature + '<h1>Our Custom Body</h1>' + signature;
} catch(ex) {
//something went wrong
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…