mailtolink
v0.1.0
Published
create mailto: links
Downloads
2
Readme
mailtolink.js
Makes mailto:
links.
In the browser:
<script src="mailtolink.js"></script>
<script>
// Set the .email-link's href to "mailto:[email protected]".
var emailLink = document.querySelector('a.email-link');
emailLink.href = mailtoLink('[email protected]');
</script>
In a CommonJS environment like Node or Browserify:
var mailtoLink = require('mailtolink');
console.log(mailtoLink('[email protected]'));
Examples
Generate a link for one email address:
mailtoLink('[email protected]')
// => mailto:[email protected]
Generate a link for multiple email addresses:
mailtoLink(['[email protected]', '[email protected]'])
// => mailto:[email protected],[email protected]
Generate a link with an email and a subject:
mailtoLink('[email protected]', { subject: '¡Hola!' })
// => mailto:[email protected]?subject=%C2%A1Hola!
Generate a link with just a subject:
mailtoLink({ subject: '¡Hola!' })
// => mailto:?subject=%C2%A1Hola!
Generate a link with a subject and a body:
mailtoLink({
subject: 'Check out this photo',
body: [
'I thought you might really enjoy this photo of a store I found:',
'',
'http://example.com/tienda.jpg',
].join('\n')
})
// => mailto:?subject=Check%20out%20this%20photo&body=I%20thought%20you%20might%20really%20enjoy%20this%20photo%20of%20a%20store%20I%20found%3A%0D%0A%0D%0Ahttp%3A%2F%2Fexample.com%2Ftienda.jpg'
Generate a link with an email, a subject, a CC, a body, and some BCCs:
mailtoLink('[email protected]', {
subject: 'Hi',
cc: '[email protected]',
bcc: ['[email protected]', '[email protected]'],
body: 'Hope you are doing well.'
})
// => mailto:[email protected]?subject=Hi&[email protected]&[email protected],[email protected]&body=Hope%20you%20are%20doing%20well.