Browsers can not contact smtp servers directly. That is why I provide a relay server, for free (donations welcome). You can now send emails directly through your own SMTP server, with a simple javascript call.
Choose the best way for you to use this service.
Easy to use, customizable
Simplest to use, no Javascript required
Do what you want, code!
1. Include directly the library (recommended for automated updates)
<script src="//smtpwebrelay.mayetsoft.fr/lib"></script>
Download smtpwebrelay.min.js
OR Download and include the library
<script src="/smtpwebrelay.min.js"></script>
2. Send emails
sendMail({ // This structure is based on Nodemailer message Configuration., with changes.
from: '[email protected]',
to : '[email protected]',
subject: 'subject test mail',
text: 'hello world',
transport: { // This structure is based on Nodemailer transport Configuration, with changes.
host: "smtp.example.com",
port: 465,
secure: true, // use TLS
auth: {
user: "username",
pass: "password"
}
},
callback: (error, result)=>{ alert(error || result);} //callback optional, falls back to Promise
});
Include this form in your page.
<form action="/send" method="POST">
<input name="from" type="hidden" value="[email protected]">
To <input name="to" type="text" placeholder="[email protected];[email protected]" required="required">
<input name="cc" type="hidden" value="[email protected]">
Subject <input name="subject" type="text" placeholder="Hello">
Text <textarea name="text" cols="30" rows="10" placeholder="Hello World"></textarea>
<input name="redirect" type="hidden" value="https://my.site.confirm.page/#confirm">
<input type="submit" value="Send Message">
<input name="transport" type="hidden"
value='{"host":"smtp.example.com","port":465,"secure":true,"auth":{"user":"username","pass":"password"}}'>
</form>
Note: The long value for the transport field represents the transport configuration as defined by the json object, then stringified to be posted as part of the form.
I however recommend getting the encrypted version of the transport object to secure your connection details on public pages.
To use, you can adapt the details and use this code in the development console of your browser.
JSON.stringify({
host: "smtp.example.com",
port: 465,
secure: true, // use TLS
auth: {
user: "username",
pass: "password"
}
});
1. Create request
const request = new XMLHttpRequest();
request.open('POST', 'https://smtpwebrelay.mayetsoft.fr/send');
2. Prepare AJAX reqest
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
request.onreadystatechange = function() { // get results when done
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
console.log('Email sent to ' + to);
}
}
3. Send the AJAX request using "URL encoded information" through the javascript function encodeURIComponent('hello world'))
request.send(
'from=from%40exemple.com'+
'&to=to%40exemple.com'+
'&subject=hello%20world'+
'&text=hello%20whole%20wide%20world!'+
'&transport='+ encodeURIComponent(JSON.stringify({
host: "smtp.example.com",
port: 465,
secure: true, // use TLS
auth: {
user: "username",
pass: "password"
}
}))
);
Spammers would love to get their hands on your SMTP server details. You should really not put them in any public page. Anybody with minimal knowledge of browsers can find those details.
That is why I created a system to encrypt your connection details in your own page. No hackable database here. You encrypt the details using the form below and this information can only be read by the relay server I provide. Event more, the information can only be used from the site you declared when encrypting the SMTP details.
A one time payment can greatly help sponsor the security of this service to you.
This library and service is specially designed to be the most flexible and as such there are multiple options.
This service is using Nodemailer internally. Most of the options of nodemailer are usable in SMTP web relay. For security reasons, all the options are filtered. Nodemailer is created by Andris Reinman.
Once the javascript client side library is included, as shown in the Usage section, you can call the global function
sendMail({/* Message object */})
to send an email with your SMTP server, from a browser.
If you don't want to use a callback, you can call the library with a Promise.
sendMail({/* Message object */}).then((r)=>{console.log(r.success, r.error)})
SMTP web relay supports the Nodemailer message configuration object.
For security, the server filters out any fields that is not allowed and accepts only {from, to, cc, bcc, subject, text, html, amp, sender, replyTo, inReplyTo, references, attachDataUrls, watchHtml, encoding, raw, textEncoding, priority, headers, messageId, date, list}
.
It also adds disableFileAccess=true
to the configuration automatically to protect itself.
For now, disableUrlAccess
is not used but may be activated in the future if the service is abused (big files, large number of requests, heavy memory usage, cost, ...).
Additional options that are not part of Nodemailer are
onebyone
: splits all the addresses listed in to
, cc
and bcc
to send the message to each recipient individually (uses to
for everyone).redirect
: when a form without using the javascript library and the email has been sent, the server can then instruct the user's browser to perform a redirect to the page listed. This should be a valid, browseable URL or your user will not be able to see the confirmation page. In case an error occur, an error message will be displayed and no redirection will take place.transport
: a Nodemailer transport configuration object, with the constraints defined in this page. For any public page, this should be encrypted using the form provided by this website.callback
: (Available only on the client-side library), this provides you with the return value {success, error} and allows your code to continue after the email has been sent. In case no callback is provided, the library wraps its response in a Promise and returns that.All of the text values in message configuration can be encrypted in advance so that they can be kept securely and used only on the intended domain. The encryption is done on the relay server. The encryption key is internal to it and is not available to anybody else. It uses AES-256-CBC. This way everything remains secure.
SMTP web relay supports the Nodemailer transport configuration object.
For security, the server filters out any fields that is not {host, port, authMethod, auth: {service, type, user, pass, type, clientId, clientSecret, refreshToken, accessToken, expires, accessUrl, serviceClient, privateKey}, secure, connectionTimeout, greetingTimeout, socketTimeout, pool, maxConnections, maxMessages, rateDelta, rateLimit, proxy}
.
Other settings such as {tls, disableFileAccess, disableUrlAccess, logger, debug, sendmail, newline, path, streamTransport, jsonTransport, ses, dsn, ctx}
are ignored when passed into a request.
If you plan on using gmail as a SMTP server, please read the note on Nodemailer's site before proceeding.
If you plan on sending bulk emails with this service, please consider hosting your own relay server. The code is available for free. You can still donate as a thank you for the code though! Also, for bulk email sending, you'll find an informative note about Delivering bulk email on Nodemailer's side
Normal SMTP servers for the general public generally come with strict limits in terms of how many emails you can send and how many addresses you can handle per day. If you are considering to send a lot of emails, you should use a SMTP server from a specialized company to ensure delivrability. It would be quite useless to spend the time sending all those emails if they never arrive or just hit the spam folder, isn't it?
For small needs, you may get away with using your normal consumer server, the one from your internet provider or email provider. Check out a list on serversmtp.com.
However, I don't really advise that. Most professional email sending services have a much better rate of delivery and offer a free quota. Try mailgun.com, sendgrid.com, serversmtp.com or mailjet.com. (I don't hold any stake in your choice. There are no referral links here.) If you want to try for free a fake smtp server, you can try mailtrap.io, develmail.com, mailcatcher.me (local installation) or mailslurper.com (local installation).
Wait, free, why? I just wanted a simple service that works for me and my projects and along the way, I found others that needed it. It's so small and cute that it would just take too much time to build a business model for this project. Hence, I decided to both offer it up for others to use and to host it (open source). As the hosting I offer actually costs me money, I am only encouraging for donations, especially if you use this for a commercial project. And, if you're generous, I may be able to get coffee to support my next open project.
Free for as long as I can afford to run the servers. I use it for a lot of my projects so it's probably going to keep going for quite a while. Subscribe below to receive updates.
Running the server does cost me money. What about helping towards those costs with a small donation? One time gift, recurent, $2, 3€, £10 millions, a thank you email, that's up to you.
For recurent donations starting 1€/month through liberapay, you will also get the right to a link to your profile or organization in the donors section!
Get the code and run your own server for free. Keep it for yourself or offer it up for others to use. The code is for a lightweight nodeJS micro-service that scales well.
Send an email with your own SMTP server and credentials. You can use javascript but it also works with simple web forms.