SmtpJS.com

Send email from Javascript

Getting started

  • 1. Include the script:
    <script src="https://smtpjs.com/v3/smtp.js">
    </script>
  • 2. Send an email using:
    Email.send({
        Host : "smtp.elasticemail.com",
        Username : "username",
        Password : "password",
        To : 'them@website.com',
        From : "you@isp.com",
        Subject : "This is the subject",
        Body : "And this is the body"
    }).then(
      message => alert(message)
    );
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({
    SecureToken : "C973D7AD-F097-4B95-91F4-40ABC5567812",
    To : 'them@website.com',
    From : "you@isp.com",
    Subject : "This is the subject",
    Body : "And this is the body"
}).then(
  message => alert(message)
);

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-standard 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 should use the promise returned from the send function. This will pass a message of "OK" for success, and an error message as failure.

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 the Attachments property:

Email.send({
    SecureToken : "C973D7AD-F097-4B95-91F4-40ABC5567812",
    To : 'them@website.com',
    From : "you@isp.com",
    Subject : "This is the subject",
    Body : "And this is the body",
	Attachments : [
	{
		name : "smtpjs.png",
		path : "https://networkprogramming.files.wordpress.com/2017/11/smtpjs.png"
	}]
}).then(
  message => alert(message)
);

Dev Tip: If you want to send an attachment in base64 format, instead of passing "path" as a property, send a "data" property in dataUri format. in dataUri format. (Example coming soon!)

Sending multiple emails:
The "To" property can be an array of email addresses, instead of just one.