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
    • Education and Science
    • Yandex Cloud Partner program
  • Pricing
  • Customer Stories
  • Documentation
  • Blog
© 2025 Direct Cursus Technology L.L.C.
Tutorials
    • All tutorials
    • URL shortener
    • Ingesting data into storage systems
    • Storing application runtime logs
    • Deploying a web application using the Java Servlet API
    • Developing a Slack bot
    • Developing a Telegram bot
    • Developing a custom integration in API Gateway
    • Developing CRUD APIs for movie services
    • Building a CI/CD pipeline in GitLab
    • Configuring CI/CD between Cloud Functions and SourceCraft
    • Working with an API gateway via WebSocket
    • Creating an interactive serverless application using WebSocket
    • Automatically copying objects from one Object Storage bucket to another
    • Visualizing logs in Grafana using the Cloud Logging plugin
    • Canary release of Cloud Functions
    • Interactive debugging of Cloud Functions
    • Creating a Node.js function using TypeScript
    • Running a containerized app in Serverless Containers
    • Streaming Yandex Cloud Postbox events to Data Streams and analyzing them using DataLens
    • Using API Gateway to set up speech synthesis in SpeechKit
    • Connecting to YDB from a Cloud Functions function in Python
    • Connecting to a YDB database from a Cloud Functions function in Node.js
    • API Gateway protection with Smart Web Security
    • Deploying a web app with JWT authorization in API Gateway and authentication in Firebase
    • Automatic data upload to Yandex SpeechSense using Yandex Workflows
    • Configuring responses in Cloud Logging and Yandex Cloud Functions
    • Setting up Workflows integration with Tracker, YandexGPT, and Yandex Cloud Postbox
    • Developing functions in Functions Framework and deploying them to Yandex Serverless Containers
    • Creating a Yandex Cloud Postbox address and checking domain ownership with Terraform
      • Go
    • Creating an AI agent with Yandex Cloud Functions

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. Serverless technologies
  2. Sending emails in Yandex Cloud Postbox using AWS SDK
  3. Go

Sending emails using AWS SDK for Go

Written by
Yandex Cloud
Updated at July 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 Go.

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 in Yandex Cloud and create a billing account:

  1. Navigate to the management console and log in to Yandex Cloud or register a new account.
  2. On the Yandex Cloud Billing page, make sure you have a linked billing account with an 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 to operate in.

Learn more about clouds and folders.

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\<username>\.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 for Go 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 go/simple/ repository.
    3. Fill out the Sender and Recipient fields in the main.go file:

      • Sender: Sender's email address.

        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: Recipient's email address, e.g., receiver@domain.com. You will need access to this email address for the next step.

    4. Go to the go/ directory.
    1. Create a directory named postbox-go and open it.

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

      package main
      
      import (
        "context"
        "fmt"
        "net/url"
        "os"
      
        "github.com/aws/aws-sdk-go-v2/aws"
        "github.com/aws/aws-sdk-go-v2/config"
        "github.com/aws/aws-sdk-go-v2/service/sesv2"
        "github.com/aws/aws-sdk-go-v2/service/sesv2/types"
        transport "github.com/aws/smithy-go/endpoints"
      )
      
      const (
        // The sender's address must be verified using Amazon SES.
        Sender = "<sender_address>"
      
        // Recipient's address.
        Recipient = "<recipient_address>"
      
        // Email subject.
        Subject = "Yandex Cloud Postbox Test via AWS SDK for Go"
      
        // HTML text of the email.
        HtmlBody = "<h1>Amazon SES Test Email (AWS SDK for Go)</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-go/'>AWS SDK for Go</a>.</p>"
      
        // Email text for email clients without HTML support.
        TextBody = "This email was sent with Yandex Cloud Postbox using the AWS SDK for Go."
      
        // Character encoding in the email.
        CharSet = "UTF-8"
      )
      
      func main() {
        cfg, err := config.LoadDefaultConfig(
          context.Background(),
        )
        if err != nil {
          fmt.Println("unable to load SDK config, " + err.Error())
          os.Exit(1)
        }
      
        client := sesv2.New(sesv2.Options{
          Region:             "ru-central1",
          EndpointResolverV2: &resolverV2{},
          Credentials: cfg.Credentials,
        })
      
        // Building the email.
        input := &sesv2.SendEmailInput{
          Destination: &types.Destination{
            ToAddresses: []string{Recipient},
          },
          Content: &types.EmailContent{
            Simple: &types.Message{
              Subject: &types.Content{
                Charset: aws.String(CharSet),
                Data:    aws.String(Subject),
              },
              Body: &types.Body{
                Html: &types.Content{
                  Charset: aws.String(CharSet),
                  Data:    aws.String(HtmlBody),
                },
                Text: &types.Content{
                  Charset: aws.String(CharSet),
                  Data:    aws.String(TextBody),
                },
              },
            },
          },
          FromEmailAddress: aws.String(Sender),
        }
      
        // Sending the email.
        ctx := context.Background()
        res, err := client.SendEmail(ctx, input)
      
        if err != nil {
          panic(err)
        }
      
        fmt.Println(*res.MessageId)
      }
      
      type resolverV2 struct{}
      
      func (*resolverV2) ResolveEndpoint(_ context.Context, _ sesv2.EndpointParameters) (
        transport.Endpoint, error,
      ) {
        u, err := url.Parse("https://postbox.cloud.yandex.net")
        if err != nil {
          return transport.Endpoint{}, err
        }
        return transport.Endpoint{
          URI: *u,
        }, nil
      }
      
      type staticCredentialsProvider struct {
        accessKeyID     string
        secretAccessKey string
      }
      
      func (s *staticCredentialsProvider) Retrieve(_ context.Context) (aws.Credentials, error) {
        return aws.Credentials{
          AccessKeyID:     s.accessKeyID,
          SecretAccessKey: s.secretAccessKey,
        }, nil
      }
      
    3. Fill out the Sender and Recipient fields in the main.go file:

      • Sender: Sender's email address.

        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: Recipient's email address, e.g., receiver@domain.com. You will need access to this email address for the next step.

    4. Create a file named go.mod and paste this code into it:

      module postbox
      
      go 1.23
      
      require (
        github.com/aws/aws-sdk-go-v2 v1.36.3
        github.com/aws/aws-sdk-go-v2/config v1.29.14
        github.com/aws/aws-sdk-go-v2/service/sesv2 v1.42.0
        github.com/aws/smithy-go v1.22.2
        github.com/emersion/go-message v0.18.2
      )
      
      require (
        github.com/aws/aws-sdk-go-v2/credentials v1.17.67 // indirect
        github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.30 // indirect
        github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.34 // indirect
        github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34 // indirect
        github.com/aws/aws-sdk-go-v2/internal/ini v1.8.3 // indirect
        github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.33 // indirect
        github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.12.3 // indirect
        github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.15 // indirect
        github.com/aws/aws-sdk-go-v2/service/sso v1.25.3 // indirect
        github.com/aws/aws-sdk-go-v2/service/ssooidc v1.30.1 // indirect
        github.com/aws/aws-sdk-go-v2/service/sts v1.33.19 // indirect
      )
      
  2. Install the dependencies:

    go mod tidy
    

    Result:

    go: downloading github.com/aws/aws-sdk-go-v2 v1.36.3
    go: downloading github.com/aws/aws-sdk-go-v2/service/sesv2 v1.42.0
    ...
    go: downloading github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.34
    
  3. Run the application:

    go run main.go
    

    Result:

    DAEBWI6L7WN5.1RLCK********@ingress2-sas
    

Check the resultCheck the result

Make sure the recipient specified in the file named main.go 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:

  • Delete the address.
  • Delete the DNS zone if you had created a resource record in it.

Was the article helpful?

Previous
Creating a Yandex Cloud Postbox address and checking domain ownership with Terraform
Next
Creating an AI agent with Yandex Cloud Functions
© 2025 Direct Cursus Technology L.L.C.