• Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript How to send bulk email using javascript by azure ACS

abidiziko99

New Coder
How to send bulk email using javascript by Azure Communication Services

JavaScript:
const { EmailClient } = require("@azure/communication-email");

const connectionString = `endpoint=${endpoint}/;accesskey=xxxxxxxxxxxxxxxxxxxxxxx`;
const client = new EmailClient(connectionString);
const sender = "[email protected]";
const emailContent = {
  subject: "Send email quick start test- JS sample",
  plainText: "Test Email from JS Send Email Sample Application\n\n This email is part of testing of email communication service. \\n Best wishes",
  html: "<html><head><title>ACS Email as a Service</title></head><body><h1>ACS Email as a Service - Html body</h1><h2>This email is part of testing of email communication service</h2></body></html>",
};
const toRecipients = {
  to: [
    { email: "[email protected]", displayName: "xxx" },
    { email: "[email protected]", displayName: "xxx" },
  ],
};

async function main() {
  try {
    const emailMessage = {
      sender: sender,
      content: emailContent,
      recipients: toRecipients,
    };

    const sendResult = await client.send(emailMessage);

    if (sendResult && sendResult.messageId) {
      // check mail status, wait for 5 seconds, check for 60 seconds.
      const messageId = sendResult.messageId;
      if (messageId === null) {
        console.log("Message Id not found.");
        return;
      }

      console.log("Send email success, MessageId :", messageId);

      let counter = 0;
      const statusInterval = setInterval(async function () {
        counter++;
        try {
          const response = await client.getSendStatus(messageId);
          if (response) {
            console.log(`Email status for {${messageId}} : [${response.status}]`);
            if (response.status.toLowerCase() !== "queued" || counter > 12) {
              clearInterval(statusInterval);
            }
          }
        } catch (e) {
          console.log("Error in checking send mail status: ",e);
        }
      }, 5000);
    } else {
      console.error("Something went wrong when trying to send this email: ", sendResult);
    }
  } catch (e) {
    console.log("################### Exception occoured while sending email #####################", e);
  }
}

main();

I want to send emails to many users without the recipients seeing who I'm sending



dev.png


Is there a solution to send mail individually and import emails from a text or excel file?
I tried a lot and I couldn't on my own

Please help and thank you in advance
 
Last edited by a moderator:

Antero360

King Coder
Staff Team
Security Analyst
How to send bulk email using javascript by Azure Communication Services

JavaScript:
const { EmailClient } = require("@azure/communication-email");

const connectionString = "endpoint=https://callandsms.communication.azure.com/;accesskey=xxxxxxxxxxxxxxxxxxxxxxx";
const client = new EmailClient(connectionString);
const sender = "[email protected]";
const emailContent = {
  subject: "Send email quick start test- JS sample",
  plainText: "Test Email from JS Send Email Sample Application\n\n This email is part of testing of email communication service. \\n Best wishes",
  html: "<html><head><title>ACS Email as a Service</title></head><body><h1>ACS Email as a Service - Html body</h1><h2>This email is part of testing of email communication service</h2></body></html>",
};
const toRecipients = {
  to: [
    { email: "[email protected]", displayName: "xxx" },
    { email: "[email protected]", displayName: "xxx" },
  ],
};

async function main() {
  try {
    const emailMessage = {
      sender: sender,
      content: emailContent,
      recipients: toRecipients,
    };

    const sendResult = await client.send(emailMessage);

    if (sendResult && sendResult.messageId) {
      // check mail status, wait for 5 seconds, check for 60 seconds.
      const messageId = sendResult.messageId;
      if (messageId === null) {
        console.log("Message Id not found.");
        return;
      }

      console.log("Send email success, MessageId :", messageId);

      let counter = 0;
      const statusInterval = setInterval(async function () {
        counter++;
        try {
          const response = await client.getSendStatus(messageId);
          if (response) {
            console.log(`Email status for {${messageId}} : [${response.status}]`);
            if (response.status.toLowerCase() !== "queued" || counter > 12) {
              clearInterval(statusInterval);
            }
          }
        } catch (e) {
          console.log("Error in checking send mail status: ",e);
        }
      }, 5000);
    } else {
      console.error("Something went wrong when trying to send this email: ", sendResult);
    }
  } catch (e) {
    console.log("################### Exception occoured while sending email #####################", e);
  }
}

main();

I want to send emails to many users without the recipients seeing who I'm sending



View attachment 1758


Is there a solution to send mail individually and import emails from a text or excel file?
I tried a lot and I couldn't on my own

Please help and thank you in advance
Hi there,

Is there a particular reason you do not want the users to see who else is getting the email?
 

cbreemer

King Coder
Your question has nothing to do with JavaScript. The solution is very simple : send your mail to some non-existent address (or to yourself, if you don't want to get an 'undeliverable' error), and put your list of recipients in the Bcc header.
 
Top