Yandex Cloud
Search
Contact UsGet started
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
  • All Services
  • System Status
    • Featured
    • Infrastructure & Network
    • Data Platform
    • Containers
    • Developer tools
    • Serverless
    • Security
    • Monitoring & Resources
    • AI Studio
    • Business tools
  • All Solutions
    • By industry
    • By use case
    • Economics and Pricing
    • Security
    • Technical Support
    • Start testing with double trial credits
    • Cloud credits to scale your IT product
    • Gateway to Russia
    • Cloud for Startups
    • Center for Technologies and Society
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Service page
Yandex Cloud Postbox
Documentation
Yandex Cloud Postbox
  • Getting started
    • All tutorials
    • Streaming Yandex Cloud Postbox events to Yandex Data Streams and analyzing them with Yandex DataLens
    • Creating a Yandex Cloud Postbox address and verifying domain ownership with Terraform
      • .NET Core
      • Go
      • JavaScript
      • Python
  • Access management
  • Pricing policy
  • Audit Trails events
  • Public materials
  • Release notes

In this article:

  • Get your cloud ready
  • Required paid resources
  • Set up resources
  • Configure a directory for authentication data
  • Using environment variables
  • Create and run the application
  • Check the result
  • How to delete the resources you created
  1. Tutorials
  2. Sending emails using the AWS SDK
  3. JavaScript

Sending emails using the AWS SDK for JavaScript

Written by
Yandex Cloud
Updated at August 14, 2025
  • Get your cloud ready
    • Required paid resources
    • Set up resources
  • Configure a directory for authentication data
    • Using environment variables
  • Create and run the application
  • Check the result
  • How to delete the resources you created

In this tutorial, you will learn how to send emails via Yandex Cloud Postbox using the AWS SDK for JavaScript.

To start sending emails:

  1. Get your cloud ready.
  2. Configure a directory for authentication data.
  3. Create and run the application.
  4. Check the result.

If you no longer need the resources you created, delete them.

Get your cloud readyGet your cloud ready

Sign up for Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or create a new account.
  2. On the Yandex Cloud Billing page, make sure you have a billing account linked and it has the ACTIVE or TRIAL_ACTIVE status. If you do not have a billing account, create one and link a cloud to it.

If you have an active billing account, you can navigate to the cloud page to create or select a folder for your infrastructure.

Learn more about clouds and folders here.

Required paid resourcesRequired paid resources

The infrastructure support costs include:

  • Fee for using Yandex Cloud Postbox (see Yandex Cloud Postbox pricing).
  • Fee for public DNS queries and DNS zones, if you are creating a resource record in Cloud DNS (see Cloud DNS pricing).

Set up resourcesSet up resources

  1. Create a service account.
  2. Assign the postbox.sender role to the service account.
  3. Create a static access key for the service account. Save the ID and secret key.
  4. Create an address.
  5. Pass a domain ownership check.

Configure a directory for authentication dataConfigure a directory for authentication data

  1. Create a directory to store the authentication data in and navigate to it:

    For macOS and Linux:

    mkdir ~/.aws/
    

    For Windows:

    mkdir C:\Users\<user_name>\.aws\
    
  2. In the .aws directory, create a file named credentials, copy the credentials you got when creating a static access key, and paste them into it:

    [default]
    aws_access_key_id = <static_key_ID>
    aws_secret_access_key = <secret_key>
    
  3. Create a file named config with the default region settings and copy the following information to it:

    [default]
    region = ru-central1
    endpoint_url = https://postbox.cloud.yandex.net
    

Using environment variablesUsing environment variables

By default, the AWS SDK uses authentication data from environment variables if they are set. These variables have priority over authentication data from the .aws/credentials file.

The following environment variables are supported:

  • AWS_ACCESS_KEY_ID: Static key ID.
  • AWS_SECRET_ACCESS_KEY: Secret key.

To set environment variables, depending on your operating system, follow these steps:

Linux/macOS
Windows

In the terminal, run this command:

export AWS_ACCESS_KEY_ID=<static_key_ID>
export AWS_SECRET_ACCESS_KEY=<secret_key>

In PowerShell, run:

$Env:AWS_ACCESS_KEY_ID=<static_key_ID>
$Env:AWS_SECRET_ACCESS_KEY=<secret_key>

Create and run the applicationCreate and run the application

  1. Get the application code:

    Repository
    Manually
    1. Clone the repository:

      git clone https://github.com/yandex-cloud-examples/yc-postbox-examples
      
    2. Navigate to the folder in the cloned javascript/ repository.
    3. In the main.js file, specify the following:

      • Sender's email address in the SENDER field.

        The sender's email domain must match the one specified in the Yandex Cloud Postbox address you created when getting started. For example, if your verified domain is yourdomain.com, you can use addresses like noreply@yourdomain.com or admin@yourdomain.com but not user@mail.yourdomain.com.

      • Recipient's email address in the RECIPIENT field, e.g., receiver@yourdomain.com. You will need access to this email address for the next step.

    1. Create a directory named postbox-javascript and open it.

    2. Create a file named main.js and paste this code into it:

      // AWS SDK for JavaScript v3 (ESM)
      import { SESv2Client, SendEmailCommand } from '@aws-sdk/client-sesv2';
      
      // The sender's address must be verified using Amazon SES.
      const SENDER = "<sender_address>";
      
      // Recipient's address.
      const RECIPIENT = "<recipient_address>";
      
      // Email subject.
      const SUBJECT = "Yandex Cloud Postbox Test via AWS SDK for JavaScript v3";
      
      // HTML text of the email.
      const HTML_BODY = `<h1>Amazon SES Test Email (AWS SDK for JavaScript v3)</h1>
      <p>This email was sent with <a href='https://yandex.cloud/en/docs/postbox/quickstart'>Yandex Cloud Postbox</a> using the 
      <a href='https://aws.amazon.com/sdk-for-javascript/'>AWS SDK for JavaScript v3</a>.</p>`;
      
      // Email text for email clients without HTML support.
      const TEXT_BODY = "This email was sent with Yandex Cloud Postbox using the AWS SDK for JavaScript v3.";
      
      // Character encoding in the email.
      const CHARSET = "UTF-8";
      
      // Main function
      async function main() {
          // Create a SES client with an endpoint for Yandex Cloud Postbox
          const client = new SESv2Client({
              region: 'ru-central1',
              endpoint: 'https://postbox.cloud.yandex.net',
              // By default, the SDK uses the default credential provider chain.
              // You can use static credentials by uncommenting and changing the following lines:
              // credentials: {
              //     accessKeyId: 'accessKeyID',
              //     secretAccessKey: 'secretAccessKey',
              // },
          });
      
          // Building the email.
          const params = {
              Destination: {
                  ToAddresses: [RECIPIENT],
              },
              Content: {
                  Simple: {
                      Subject: {
                          Charset: CHARSET,
                          Data: SUBJECT,
                      },
                      Body: {
                          Html: {
                              Charset: CHARSET,
                              Data: HTML_BODY,
                          },
                          Text: {
                              Charset: CHARSET,
                              Data: TEXT_BODY,
                          },
                      },
                  },
              },
              FromEmailAddress: SENDER,
          };
      
          try {
              // Creating a command.
              const command = new SendEmailCommand(params);
      
              // Sending the email.
              const data = await client.send(command);
              console.log(data.MessageId);
          } catch (err) {
              console.error("Error sending email:", err);
              throw err;
          }
      }
      
      // Running the main function.
      main().catch(err => {
          console.error("Unhandled error:", err);
          process.exit(1);
      });
      
    3. In the main.js file, specify the following:

      • Sender's email address in the SENDER field.

        The sender's email domain must match the one specified in the Yandex Cloud Postbox address you created when getting started. For example, if your verified domain is yourdomain.com, you can use addresses like noreply@yourdomain.com or admin@yourdomain.com but not user@mail.yourdomain.com.

      • Recipient's email address in the RECIPIENT field, e.g., receiver@yourdomain.com. You will need access to this email address for the next step.

    4. Create a file named package.json and paste this code into it:

      {
        "name": "yc-postbox-example",
        "version": "1.0.0",
        "description": "Example of sending emails through Yandex Cloud Postbox using AWS SDK for JavaScript",
        "main": "main.js",
        "type": "module",
        "scripts": {
          "start": "node main.js"
        },
        "dependencies": {
          "@aws-sdk/client-sesv2": "^3.821.0"
        },
        "license": "MIT"
      }
      
  2. Install the dependencies:

    npm install
    

    Result:

    added 79 packages, and audited 80 packages in 3s
    
    3 packages are looking for funding
      run `npm fund` for details
    
    found 0 vulnerabilities
    
  3. Run the application:

    npm start
    

    Result:

    > yc-postbox-example@1.0.0 start
    > node main.js
    
    DB6TZYXAOBH1.2E2Q5********@ingress2-klg
    

Check the resultCheck the result

Make sure the recipient specified in the file named main.js in the RECIPIENT field has received an email with the specified parameters.

How to delete the resources you createdHow to delete the resources you created

To stop paying for the resources you created:

  1. Delete the address.
  2. Delete the DNS zone if you created a resource record in it.

Was the article helpful?

Previous
Go
Next
Python
© 2025 Direct Cursus Technology L.L.C.