X Enterprises
fastify-xemail

sendBulk

Send the same email to multiple recipients in a single SendGrid API call.

sendBulk

Send the same email to multiple recipients in a single API call using sgMail.sendMultiple. All recipients receive identical content. For per-recipient personalization, use sendPersonalizedBulk.

Signature

fastify.xEmail.sendBulk(
  to: string[],
  subject: string,
  html: string
): Promise<{ success: boolean; count: number; statusCode: number }>

Params

NameTypeRequiredDescription
tostring[]YesNon-empty array of recipient email addresses.
subjectstringYesEmail subject line.
htmlstringYesHTML email body.

Returns

Promise<{ success: boolean; count: number; statusCode: number }>

PropertyTypeDescription
successbooleanAlways true on resolved promise.
countnumberNumber of recipients in the to array.
statusCodenumberSendGrid HTTP response status (typically 202).

Throws

  • [xEmail] 'to' must be a non-empty array for sendBulk(). — missing or empty to.
  • [xEmail] 'subject' is required for sendBulk().
  • [xEmail] 'html' is required for sendBulk().
  • [xEmail] Failed to send bulk emails: <reason> — SendGrid API error.

Examples

Basic — notify all team members

fastify.post("/announcements", async (request) => {
  const { subject, body } = request.body;
  const teamEmails = await db.users.getTeamEmails();

  const result = await fastify.xEmail.sendBulk(
    teamEmails,
    subject,
    `<div style="font-family: sans-serif;"><p>${body}</p></div>`
  );

  return { sent: result.count, statusCode: result.statusCode };
});

Realistic — weekly digest to all active subscribers

fastify.post("/newsletters/send-digest", async (request) => {
  const digest = await buildWeeklyDigest();
  const subscribers = await db.users.getActiveSubscribers();
  const emails = subscribers.map((s) => s.email);

  const result = await fastify.xEmail.sendBulk(
    emails,
    `Weekly Digest — ${digest.weekLabel}`,
    digest.html
  );

  await db.newsletters.logSend({
    recipientCount: result.count,
    sentAt: new Date(),
  });

  return { sent: result.count };
});

See Also

  • send-personalized-bulk — Different content per recipient with partial-failure handling
  • send — Send to a single recipient or small list

AI Context

package: "@xenterprises/fastify-xemail"
method: fastify.xEmail.sendBulk(recipients, subject, html, options?)
use-when: Send the same email content to multiple recipients in a single SendGrid API call
params: recipients (string[]), subject, html, options (from, cc, bcc)
returns: Promise<void>
Copyright © 2026