If you have ever sent an email from a web application, you know that it is not necessarily very natural and that you must also install tools like sendmail…etc.

The free project SMTPJS proposes to work around this problem by sending your emails directly via SMTP using a simple JavaScript script that can be inserted into your web pages and of course to retrieve callbacks to find out if the messages have been correctly transmitted.

Time saving and accessible to beginners.

To do this, include this code in the header of your page:

<script src="https://smtpjs.com/v3/smtp.js"></script>

Then send an email like this:

Email.send({
    Host : "smtp.yourisp.com",
    Username : "username",
    Password : "password",
    To : '[email protected]',
    From : "[email protected]",
    Subject : "This is the subject",
    Body : "And this is the body"
}).then(
  message => alert(message)
);

You will obviously need to have accessible SMTP access. And you will not have missed it, if the code is put in a web page, we will see the password you use for the SMTP, which is not cool at all.

This is why SmtpJS goes through the ElasticMail service which offers an authentication token allowing the script to be used without revealing a login/password pair. Which would give this for example:

Email.send({
    SecureToken : "C973D7AD-F097-4B95-91F4-40ABC5567812",
    To : '[email protected]',
    From : "[email protected]",
    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)
);

This will obviously not suit all needs, but in some cases, it is still much easier to send mail with SMTP JS.

5/5 - (1 vote)