SmtpJS.com

Send email from Javascript

Getting started

  • 1. Include the script:
    <script src="https://smtpjs.com/v2/smtp.js">
    </script>
  • 2. Send an email using:
    Email.send("from@you.com",
    "to@them.com",
    "This is a subject",
    "this is the body",
    "smtp.yourisp.com",
    "username",
    "password");
No SMTP server?
Setup an SMTP server here

Security

Whoa!, wait a minute. I don't want my SMTP credentials visible to the world!

We've thought of that, so instead you can encrypt your SMTP credentials, and lock it to a single domain, and pass a secure token instead of the credentials instead, for example:

Email.send("from@you.com",
"to@them.com",
"This is a subject",
"this is the body",
{token: "63cb3a19-2684-44fa-b76f-debf422d8b00"});

Note: By default, the SMTP connection is secure (STARTTLS) and over port 25. If you need to use an SMTP server that does not accepts secure connections, or in on a non-standart port, like 587, then use the button above "Encrypt your SMTP Credentials" to store advanced configuration.
Need an SMTP server:
If you don't have access to an SMTP server, you can create one by opening an account at Elastic Email.com, then pressing Settings > SMTP/API, and using the SMTP configuration shown.
Get SMTP Credentials

Anti Spam

We don't like spam. Nobody does.

We have a zero tolerance for spam. If you get one spam report, we close your account. Sorry about that, but this is a free service, and we're not taking any heat for you.

Report Spam

Callbacks

If your code needs to know when the email is sent before continuing, then you can use an optional callback parameter. Use the following code example if you are not using saved credentials:

Email.send(
    "from@you.com",
    "to@them.com",
    "Subject",
    "Body",
    "host.yourisp.com",
    "username",
    "password",
    function done(message) { alert("sent") }    
);
Or, if you are using stored credentials:
Email.send(
    "from@you.com",
    "to@them.com",
    "Subject",
    "Body",
    {
        token: "your-token",
        callback: function done(message) { alert("sent") }   
    }
);

It's free!

This is a free script, no usage restrictions. You can include it license free, in any project, either commercial or non commercial.

Attachments:
Want to send with attachments?, use sendWithAttachment:

Email.sendWithAttachment(
    "from@you.com",
    "to@them.com",
    "Subject",
    "Body",
    "host.yourisp.com",
    "username",
    "password",
    "http://url-where-your-attachment-file-is-stored");

Dev Tip: If you want to send an attachment in base64 format, the url can be in dataUri format. See this blog post for sample code.