i use script smtp.js. There is a property "To" in the documentation it says i need to enter an array.
I tried To: ['[email protected]', '[email protected]'],
That does not work. I am looking for the right syntax with no luck so far, anyone a hint please?
Regards, Jan
CodePudding user response:
You can do that using pass array in To
Here down is demo:
const addresses = ['[email protected]','[email protected]','[email protected]'];
let index, len;
for (index = 0; index < addresses.length; index ) {
let email = addresses[index];
Email.send({
Host: "smtp.gmail.com",
Username : "Your Gmail Address",
Password : "Your Gmail Password",
To : email,
From : "sender’s email address",
Subject : "email subject",
Body : "email body",
}).then(
message => alert("mail sent successfully")
);
}
CodePudding user response:
Its string only like to: '[email protected], [email protected]',
function sendEmail() {
Email.send({
Host: "smtp.gmail.com",
Username: "sender@email_address.com",
Password: "Enter your password",
To: '[email protected], [email protected]',
From: "sender@email_address.com",
Subject: "Sending Email using javascript",
Body: "Well that was easy!!",
Attachments: [
{
name: "File_Name_with_Extension",
path: "Full Path of the file"
}]
})
.then(function (message) {
alert("Mail has been sent successfully")
});
}
CodePudding user response:
function sendEmail(toemail=[]) {
Email.send({
...
To: toemail.join(), // it will join array value with ',' and return string
...
}).then().catch();
}
An example is of join
var emails = ['[email protected]','[email protected]'];
console.log(emails.join())
log will be
[email protected],[email protected]