Problem
How do I send an email using the outMail API in Javascript?
How do I send an email using the outMail API in jQuery?
How do I send an email in Javascript using a RESTful API?
Solution
The following example of code assumes you have already got a fully functional webserver and you have working knowledge of Javascript and the jQuery framework.
Example code outmail-api.html
<!DOCTYPE html>
<html>
<head>
<title>outMail API - JavaScript / jQuery Example</title>
<meta charset="UTF-8" />
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
</head>
<body>
<script language="JavaScript">
$(document).ready(function() {
$("#btn").on("click", function() {
$.ajax({
url: "https://api.smtp-engine.com/outmail/v1/email/send",
method: "POST",
headers: { "Content-Type": "application/json" },
data: JSON.stringify({
api_key: "YOUR-API-KEY-SECRET",
to: ["Someone <someone@example.com>"],
sender: "My Name <me@example.com>",
subject: "Sending via Outmail",
text_body: "This is the text message body",
html_body: "<body><h1>This is the message</h1></body>"
})
})
.done(function(result) {
console.log(result);
})
.fail(function(err) {
throw err;
});
});
});
</script>
<a href="#" id="btn"><h1>Click me</h1> </a>
</body>
</html>
Summary of server details
Outgoing server |
mxXXXXXX.smtp-engine.com As provided in your signup email. |
Outgoing server protocol |
SMTP |
Outgoing server port |
25, 465, 587, 2525 or 8025 |
Authentication Type |
Basic Authentication, SSL and TLS supported |
Username |
As provided |
Password |
As provided |