universal-create-mailto-href

A typed and tested function to generate Mailto links in any environment(universal).

Usage no npm install needed!

<script type="module">
  import universalCreateMailtoHref from 'https://cdn.skypack.dev/universal-create-mailto-href';
</script>

README

universal-create-mailto-href

forthebadge forthebadge

Help your users send meaningful emails from your application with just one click

 

Install

npm install universal-create-mailto-href

Sending emails can be a chore. You have to figure out who to send it to, decide if anyone needs to be on CC or even BCC, put a meaningful subject and of course write the body.

As developers we can help our users with this struggle! By thinking of who our users want to reach and what they want to say we can create powerful templates by just using HTML links and a bit of creativity. Normally this requires some string interpolation, headscratching and looking out for edge cases, so why not use this fully tested package to help you along?

no information lost in URI encodings or typos in string interpolation

 

Basic usage

import { createMailtolHref } from 'universal-create-mailto-href';

const href = createMailtolHref({
    emails: ['person@test.com'],
    cc: ['support@org.io'],
    subject: 'I need help'
})
// mailto:person@test.com?cc=person@test.com

Advanced usage

import { createMailtolHref } from 'universal-create-mailto-href';

const href = createMailtolHref({
    emails: ['user1@test.com', 'user2@test.com'],
    cc: ['support@org.io'],
    bcc: ['person1@test1.com', 'person2@test2.com', 'person3@test3.com', 'person4@test4.com' ],
    subject: 'Hello everyone!',
    body: 'What do you think about feature X?'
})
// mailto:user1@test.com,user2@test.com?cc=support@org.io&bcc=person1@test1.com,person2@test2.com,person3@test3.com,person4@test4.com&subject=Hello%20everyone!&body=What%20do%20you%20think%20about%20feature%20X%3F

Let me know what you build!

Kris