alex
alex

Reputation: 235

Prepopulating an email message using javascript

I have an application which displays a list of users , When clicking on the email button I want the email client to open up with a prepopulated message ( I make the message using javascript) , I am not sure about how to prepopulate the message

Any help would be appreciated

I would post snippets , but honestly I dnt know how to start with this

Upvotes: 2

Views: 1939

Answers (2)

Dennis
Dennis

Reputation: 32608

URI encode the text and then append it to a mailto: URL:

<a href='mailto:[email protected]?body=text%20here'>Send mail!</a>

More generally, you can use:

  • subject
  • body (multiple body parameters will put each on a new line)
  • CC
  • BCC

with an ampersand (&) between each pair.

mailto:[email protected]?subject=Hi&body=some%20text

Upvotes: 8

Esailija
Esailija

Reputation: 140244

You can use jQuery to find all the links that have mailto:, then process their href to add the message body:

$("a[href^='mailto:']").prop( "href", function(i, prop){
     return prop + "?body=" + encodeURIComponent( "Your message here" );
});

Demo:

http://jsfiddle.net/6qXrU/

Upvotes: 2

Related Questions