user3378165
user3378165

Reputation: 6916

Email with signature Javascript

Why does the following code removes the default Outlook signature?

function GetMailToInfo(attachment, body) {
    attachment = attachment ? attachment + lineBreak + lineBreak : lineBreak;
    body += lineBreak + attachment;
    window.location.href = "mailto:" + emailTo + "?subject=" + self.subject() + "&body=" + body;
}

I'm trying to generate an email with the following code but for some reason the email is being opened without the user's default signature.

Any idea on how to solve that?


Per @Dmitry Streblechenko's answer:

This is my edited code but the email still opens without the signature:

var outlook = new ActiveXObject('Outlook.Application');
var email = outlook.CreateItem(0);
var insp = email.GetInspector;
email.Subject = self.subject();
email.Display();
email.HTMLBody = body;

Upvotes: 1

Views: 1824

Answers (1)

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66276

Because you are setting the message body. If you don't specify the body, the signature will be added.

There is no way to do what you need with a mailto url. You will need to use the Outlook Object Model.

Create (new ActiveXObject()) an instance of the Outlook.Application object, use Application.CreateItem(0) to create a new message, set the Subject/To/CC/BCC properties, call MailItem.Display(). At that point Outlook will add the signature. Now read the HTMLBody property, merge it with your own text, then set the HTMLBody property back. You can use the Body property (easy to merge the signature with your own data), but then you'll lose the formatting.

Upvotes: 2

Related Questions