| 1 | import type * as sesv2 from "@distilled.cloud/aws/sesv2"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | import * as Binding from "../../Binding.ts"; |
| 4 | import type { ConfigurationSet } from "./ConfigurationSet.ts"; |
| 5 | import type { EmailIdentity } from "./EmailIdentity.ts"; |
| 6 | |
| 7 | /** |
| 8 | * The `sendEmail` request with the binding-injected members removed: |
| 9 | * `ConfigurationSetName` comes from the bound configuration set, and |
| 10 | * `FromEmailAddress` defaults to the bound identity (override it for domain |
| 11 | * identities, e.g. `hello@{domain}`). |
| 12 | */ |
| 13 | export interface SendEmailRequest extends Omit< |
| 14 | sesv2.SendEmailRequest, |
| 15 | "ConfigurationSetName" |
| 16 | > {} |
| 17 | |
| 18 | /** |
| 19 | * Runtime binding for `sesv2:SendEmail`. |
| 20 | * |
| 21 | * Bind this operation to an `EmailIdentity` (and optionally a |
| 22 | * `ConfigurationSet`) inside a function runtime to get a callable that sends |
| 23 | * simple, raw, or templated email. The binding grants the function |
| 24 | * `ses:SendEmail` (and the raw/templated variants) scoped to the identity, |
| 25 | * the account's templates, and the configuration set. |
| 26 | * |
| 27 | * For an email-address identity, `FromEmailAddress` defaults to the identity |
| 28 | * itself. For a domain identity, pass an address at the domain explicitly. |
| 29 | * |
| 30 | * Note: while the account is in the SES sandbox, both the sender identity |
| 31 | * must be verified and every recipient must be a verified identity or the |
| 32 | * SES mailbox simulator (e.g. `success@simulator.amazonses.com`). |
| 33 | * ### Sending Email |
| 34 | * **Example:** Send a Simple Message |
| 35 | * ```typescript |
| 36 | * // init |
| 37 | * const sendEmail = yield* SES.SendEmail(identity); |
| 38 | * |
| 39 | * // runtime |
| 40 | * const result = yield* sendEmail({ |
| 41 | * Destination: { ToAddresses: ["success@simulator.amazonses.com"] }, |
| 42 | * Content: { |
| 43 | * Simple: { |
| 44 | * Subject: { Data: "Hello" }, |
| 45 | * Body: { Text: { Data: "Hello from SES." } }, |
| 46 | * }, |
| 47 | * }, |
| 48 | * }); |
| 49 | * // result.MessageId |
| 50 | * ``` |
| 51 | * |
| 52 | * **Example:** Send Through a Configuration Set |
| 53 | * ```typescript |
| 54 | * const sendEmail = yield* SES.SendEmail(identity, configSet); |
| 55 | * ``` |
| 56 | * |
| 57 | * **Example:** Send a Templated Message |
| 58 | * ```typescript |
| 59 | * const result = yield* sendEmail({ |
| 60 | * Destination: { ToAddresses: ["customer@example.com"] }, |
| 61 | * Content: { |
| 62 | * Template: { |
| 63 | * TemplateName: "welcome-template", |
| 64 | * TemplateData: JSON.stringify({ name: "Ada" }), |
| 65 | * }, |
| 66 | * }, |
| 67 | * }); |
| 68 | * ``` |
| 69 | * |
| 70 | * @binding |
| 71 | */ |
| 72 | export interface SendEmail extends Binding.Service< |
| 73 | SendEmail, |
| 74 | "AWS.SES.SendEmail", |
| 75 | <I extends EmailIdentity>( |
| 76 | identity: I, |
| 77 | configurationSet?: ConfigurationSet, |
| 78 | ) => Effect.Effect< |
| 79 | ( |
| 80 | request: SendEmailRequest, |
| 81 | ) => Effect.Effect<sesv2.SendEmailResponse, sesv2.SendEmailError> |
| 82 | > |
| 83 | > {} |
| 84 | export const SendEmail = Binding.Service<SendEmail>("AWS.SES.SendEmail"); |