#SMTPJS now supports multiple attachments, ReplyTo and sender name
In case you’ve missed it, SMTPJS.com has just released the V3 Library, this offers a cleaner object model, promises, and new features, such as multiple attachments, Reply-to, and sender name
Here’s an example on how to send multiple attachments:
Email.send({
SecureToken : “XXXXX-XXXX-XXXX-XXXX-XXXXXXX”,
To : “recipient@website.com”,
From : “sender@website.com”,
FromName: “Joe Sender”,
ReplyAddress: “noreply@website.com”,
Subject : “This is the subject”,
Body : “This is the body”,
Attachments : [
{
name : “padlock.png”,
path : “https://www.smtpjs.com/img/ipad.png”
},
{
name : “spam.png”,
path : “https://www.smtpjs.com/img/iphone.png”
}
]
}).then(
message => alert(message)
);
Obviously, you need to change the secureToken property above, or pass in naked SMTP credentials.
Here’s another example, imagine you want to offer an upload form, so people can upload a file to be sent to you – without putting the file on your server.
First, here’s the required line of HTML:
<input type=”file” id=”fileupload” onchange=”uploadFileToServer()” />
Then here’s the uploadFileToServer() method;
function uploadFileToServer() {
var file = event.srcElement.files[0];
var reader = new FileReader();
reader.readAsBinaryString(file);
reader.onload = function () {
var datauri = “data:” + file.type + “;base64,” + btoa(reader.result);
Email.send({
SecureToken : “XXXX-XXXX-XXXX-XXXX-XXXX”,
To : “recipient@website.com”,
From : “sender@isp.com”,
Subject : “The subject”,
Body : “See file attached”,
Attachments : [
{
name : file.name,
data : datauri
}
]
}).then(
message => alert(message)
);
};
reader.onerror = function() {
console.log(‘there are some problems’);
};
}
Thanks for your sharing easy/free software.
btw, how can I send email as HTML page rather than message or attachment
Regards
LikeLike
Hi,
The body can be in HTML format, you could put a there for a new line, for example.
If you want to have a complex, richly formatted email, then the best thing to do is use a templating engine like Mustache.js, and define the email as a hidden div on the page
Fiach
LikeLike
Thanks for your quick reply
Could you show a simple example about “body can be in HTML format”?
Best,
Jin
LikeLike
it can send email as HTML page?
LikeLike