Skip to main content
Glama
email.ts1.73 kB
// SPDX-FileCopyrightText: Copyright Orangebot, Inc. and Medplum contributors // SPDX-License-Identifier: Apache-2.0 import { SendEmailCommand, SESv2Client } from '@aws-sdk/client-sesv2'; import { badRequest, normalizeErrorString, OperationOutcomeError } from '@medplum/core'; import type Mail from 'nodemailer/lib/mailer'; import { getConfig } from '../../config/loader'; import { addressToString, buildAddresses, buildRawMessage } from '../../email/utils'; /** * Sends an email via AWS SES. * @param options - The nodemailer options. */ export async function sendEmailViaSes(options: Mail.Options): Promise<void> { const config = getConfig(); const fromAddress = addressToString(options.from); const toAddresses = buildAddresses(options.to); const ccAddresses = buildAddresses(options.cc); const bccAddresses = buildAddresses(options.bcc); const replyToAddresses = buildAddresses(options.replyTo); let msg: Uint8Array; try { msg = await buildRawMessage(options); } catch (err) { throw new OperationOutcomeError(badRequest('Invalid email options: ' + normalizeErrorString(err)), { cause: err }); } const sesClient = new SESv2Client({ region: config.awsRegion }); try { await sesClient.send( new SendEmailCommand({ FromEmailAddress: fromAddress, Destination: { ToAddresses: toAddresses, CcAddresses: ccAddresses, BccAddresses: bccAddresses, }, ReplyToAddresses: replyToAddresses, Content: { Raw: { Data: msg, }, }, }) ); } catch (err) { throw new OperationOutcomeError(badRequest('Error sending email: ' + normalizeErrorString(err)), { cause: err }); } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/medplum/medplum'

If you have feedback or need assistance with the MCP directory API, please join our Discord server