Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save BrianSigafoos/ee58c1aa247c20761f28004a9c4c6e56 to your computer and use it in GitHub Desktop.

Select an option

Save BrianSigafoos/ee58c1aa247c20761f28004a9c4c6e56 to your computer and use it in GitHub Desktop.
Convert AWS IAM credentials to AWS SMTP credentials

Convert AWS IAM credentials to AWS SMTP credentials

You will want to use AWS SES via SMTP when you're launching an app that sends out emails of any kind (user registrations, email notifications, etc). For example, I have used this configuration on various Ruby on Rails apps, but it's basic SMTP configuration.

There are two ways to go about this:

Luckily, you found these MD files and the NOT SO EASY WAY is suddenly copy-pasta. sudo yum....

Assuming you've already set up your SES Policy on your IAM User:

    {
      "Version": "2012-10-17",
      "Statement": [
        {
          "Effect":"Allow",
          "Action":["ses:SendEmail", "ses:SendRawEmail"],
          "Resource":"*"
        }
      ]
    }

Go ahead and drop this into an bash session and pass in your IAM user's secret key to get back your SMTP password :)

Ruby

    require 'openssl'
    require 'base64'

    def aws_iam_smtp_password_generator(secret)
      message = "SendRawEmail"
      versionInBytes = "\x02"
      signatureInBytes = OpenSSL::HMAC.digest('sha256', secret, message)
      signatureAndVer = versionInBytes + signatureInBytes
      smtpPassword = Base64.encode64(signatureAndVer)
    end

PHP

    <?php

      function aws_iam_smtp_password_generator($secret) {
        $message = "SendRawEmail";
        $versionInBytes = chr(2);
        $signatureInBytes = hash_hmac('sha256', $message, $secret, true);
        $signatureAndVer = $versionInBytes.$signatureInBytes;
        $smtpPassword = base64_encode($signatureAndVer);

        return $smtpPassword;
      }

    ?>

Python

    # TODO

Java

I'm not a Java programmer, yet, but AWS's documentation [http://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-credentials.html#smtp-credentials-convert] has a snippet you can use

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment