Skip to content

email ​

Send email from Agency code through Resend, SendGrid, or Mailgun. Each provider reads its own API key from the environment: RESEND_API_KEY, SENDGRID_API_KEY, or MAILGUN_API_KEY plus MAILGUN_DOMAIN (and optional MAILGUN_REGION = "us" | "eu").

ts
import { sendWithResend } from "std::messaging/email"

node main() {
  const result = sendWithResend(
    from: "you@yourdomain.com",
    to: "friend@example.com",
    subject: "Hello!",
    text: "Hey, how are you?"
  )
  print(result)
}

Use .partial to lock down who an agent can email:

ts
const teamEmail = sendWithResend.partial(
  from: "noreply@myco.com",
  allowList: ["team@myco.com", "alerts@myco.com"]
)

Effects ​

std::sendEmail ​

ts
@always(to)
effect std::sendEmail {
  from: string;
  to: string;
  subject: string
}

(source)

Functions ​

sendWithResend ​

ts
sendWithResend(
  from: string,
  to: string,
  subject: string,
  html: string = "",
  text: string = "",
  cc: string = "",
  bcc: string = "",
  replyTo: string = "",
  apiKey: string = "",
  allowList: string[] = [],
  blockList: string[] = [],
): Result raises <std::sendEmail>

Send an email through Resend.

Configure a verified sender and a Resend API key before sending.

Parameters:

NameTypeDefaultDescription
fromstringAn email address authorized to send through this provider.
tostring
subjectstring
htmlstring""An HTML message body, which may accompany a plain-text alternative.
textstring""A plain-text message body, which may accompany an HTML version.
ccstring""One optional copy recipient address.
bccstring""One optional hidden-copy recipient address.
replyTostring""Direct replies to this address instead of the sender.
apiKeystring""Leave empty to use RESEND_API_KEY.
allowListstring[][]Limit to, cc, and bcc to these addresses, or leave empty for no allow restriction.
blockListstring[][]Reject any to, cc, or bcc address on this list, even if allowed.

Returns: Result

Throws: std::sendEmail

Needs: network

(source)

sendWithSendGrid ​

ts
sendWithSendGrid(
  from: string,
  to: string,
  subject: string,
  html: string = "",
  text: string = "",
  cc: string = "",
  bcc: string = "",
  replyTo: string = "",
  apiKey: string = "",
  allowList: string[] = [],
  blockList: string[] = [],
): Result raises <std::sendEmail>

Send an email through SendGrid.

Configure a verified sender and a SendGrid API key before sending.

Parameters:

NameTypeDefaultDescription
fromstringAn email address authorized to send through this provider.
tostring
subjectstring
htmlstring""An HTML message body, which may accompany a plain-text alternative.
textstring""A plain-text message body, which may accompany an HTML version.
ccstring""One optional copy recipient address.
bccstring""One optional hidden-copy recipient address.
replyTostring""Direct replies to this address instead of the sender.
apiKeystring""Leave empty to use SENDGRID_API_KEY.
allowListstring[][]Limit to, cc, and bcc to these addresses, or leave empty for no allow restriction.
blockListstring[][]Reject any to, cc, or bcc address on this list, even if allowed.

Returns: Result

Throws: std::sendEmail

Needs: network

(source)

sendWithMailgun ​

ts
sendWithMailgun(
  from: string,
  to: string,
  subject: string,
  html: string = "",
  text: string = "",
  cc: string = "",
  bcc: string = "",
  replyTo: string = "",
  apiKey: string = "",
  domain: string = "",
  region: string = "",
  allowList: string[] = [],
  blockList: string[] = [],
): Result raises <std::sendEmail>

Send an email through Mailgun.

Configure a Mailgun sending domain and API key before sending.

Parameters:

NameTypeDefaultDescription
fromstringAn email address authorized to send through this provider.
tostring
subjectstring
htmlstring""An HTML message body, which may accompany a plain-text alternative.
textstring""A plain-text message body, which may accompany an HTML version.
ccstring""One optional copy recipient address.
bccstring""One optional hidden-copy recipient address.
replyTostring""Direct replies to this address instead of the sender.
apiKeystring""Leave empty to use MAILGUN_API_KEY.
domainstring""Leave empty to use MAILGUN_DOMAIN.
regionstring""Use "eu" for the EU endpoint, or empty to use MAILGUN_REGION then "us".
allowListstring[][]Limit to, cc, and bcc to these addresses, or leave empty for no allow restriction.
blockListstring[][]Reject any to, cc, or bcc address on this list, even if allowed.

Returns: Result

Throws: std::sendEmail

Needs: network

(source)