Skip to content

Instantly share code, notes, and snippets.

@chrisroos
Last active January 25, 2022 20:24
Show Gist options
  • Select an option

  • Save chrisroos/6b32b07aefa010526f7e5cfe58d61978 to your computer and use it in GitHub Desktop.

Select an option

Save chrisroos/6b32b07aefa010526f7e5cfe58d61978 to your computer and use it in GitHub Desktop.

Revisions

  1. chrisroos revised this gist Apr 30, 2018. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion 2018-04-30-rails-and-aws-ses.md
    Original file line number Diff line number Diff line change
    @@ -40,9 +40,11 @@ Ports 25 and 587 require `enable_starttls_auto` to be set to `true`, and for `tl

    Port 465 ignores `enable_starttls_auto` and requires either `tls` or `ssl` to be set to `true`.

    This relates to the [Connecting to the Amazon SES SMTP Endpoint documentation](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/smtp-connect.html) which says that SES supports STARTTLS on ports 25, 587 and 2587, and supports TLS on ports 465 and 2465.

    ## Results

    | Port | Enable StartTLS Auto | TLS | SSL | Outcome |
    | Port | Enable STARTTLS Auto | TLS | SSL | Outcome |
    | ---- | -------------------- | ----- | ----- | ------- |
    | 25 | True | True | True | `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol` |
    | 25 | True | True | False | `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol` |
  2. chrisroos revised this gist Apr 30, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions 2018-04-30-rails-and-aws-ses.md
    Original file line number Diff line number Diff line change
    @@ -34,14 +34,14 @@ config.action_mailer.smtp_settings = {
    $ rails r "UserMailer.with({}).welcome_email.deliver_now"
    ```

    ## Results

    In summary:
    ## Result summary

    Ports 25 and 587 require `enable_starttls_auto` to be set to `true`, and for `tls` and `ssl` to be set to `false`.

    Port 465 ignores `enable_starttls_auto` and requires either `tls` or `ssl` to be set to `true`.

    ## Results

    | Port | Enable StartTLS Auto | TLS | SSL | Outcome |
    | ---- | -------------------- | ----- | ----- | ------- |
    | 25 | True | True | True | `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol` |
  3. chrisroos revised this gist Apr 30, 2018. 1 changed file with 16 additions and 16 deletions.
    32 changes: 16 additions & 16 deletions 2018-04-30-rails-and-aws-ses.md
    Original file line number Diff line number Diff line change
    @@ -44,27 +44,27 @@ Port 465 ignores `enable_starttls_auto` and requires either `tls` or `ssl` to be

    | Port | Enable StartTLS Auto | TLS | SSL | Outcome |
    | ---- | -------------------- | ----- | ----- | ------- |
    | 25 | True | True | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 25 | True | True | False | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 25 | True | False | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 25 | True | True | True | `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol` |
    | 25 | True | True | False | `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol` |
    | 25 | True | False | True | `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol` |
    | 25 | True | False | False | Email sent correctly |
    | 25 | False | False | False | Net::SMTPAuthenticationError: 530 Must issue a STARTTLS command first |
    | 25 | False | True | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 25 | False | True | False | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 25 | False | False | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 25 | False | False | False | `Net::SMTPAuthenticationError: 530 Must issue a STARTTLS command first` |
    | 25 | False | True | True | `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol` |
    | 25 | False | True | False | `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol` |
    | 25 | False | False | True | `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol` |
    | 465 | True | True | True | Email sent correctly |
    | 465 | True | True | False | Email sent correctly |
    | 465 | True | False | True | Email sent correctly |
    | 465 | True | False | False | Net::ReadTimeout: Net::ReadTimeout |
    | 465 | False | False | False | Net::ReadTimeout: Net::ReadTimeout |
    | 465 | True | False | False | `Net::ReadTimeout: Net::ReadTimeout` |
    | 465 | False | False | False | `Net::ReadTimeout: Net::ReadTimeout` |
    | 465 | False | True | True | Email sent correctly |
    | 465 | False | True | False | Email sent correctly |
    | 465 | False | False | True | Email sent correctly |
    | 587 | True | True | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 587 | True | True | False | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 587 | True | False | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 587 | True | True | True | `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol` |
    | 587 | True | True | False | `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol` |
    | 587 | True | False | True | `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol` |
    | 587 | True | False | False | Email sent correctly |
    | 587 | False | False | False | Net::SMTPAuthenticationError: 530 Must issue a STARTTLS command first |
    | 587 | False | True | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 587 | False | True | False | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 587 | False | False | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 587 | False | False | False | `Net::SMTPAuthenticationError: 530 Must issue a STARTTLS command first` |
    | 587 | False | True | True | `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol` |
    | 587 | False | True | False | `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol` |
    | 587 | False | False | True | `OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol` |
  4. chrisroos revised this gist Apr 30, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions 2018-04-30-rails-and-aws-ses.md
    Original file line number Diff line number Diff line change
    @@ -43,6 +43,7 @@ Ports 25 and 587 require `enable_starttls_auto` to be set to `true`, and for `tl
    Port 465 ignores `enable_starttls_auto` and requires either `tls` or `ssl` to be set to `true`.

    | Port | Enable StartTLS Auto | TLS | SSL | Outcome |
    | ---- | -------------------- | ----- | ----- | ------- |
    | 25 | True | True | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 25 | True | True | False | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 25 | True | False | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
  5. chrisroos revised this gist Apr 30, 2018. 1 changed file with 39 additions and 85 deletions.
    124 changes: 39 additions & 85 deletions 2018-04-30-rails-and-aws-ses.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,6 @@
    I added two verified email addresses to SES so that I could send emails from/to them while in the SES Sandbox.
    # Testing Rails ActionMailer and AWS SES

    I added two verified email addresses to AWS SES so that I could send emails from/to them while in the SES Sandbox.

    # UserMailer

    @@ -12,104 +14,56 @@ class UserMailer < ApplicationMailer
    end
    ```

    # Using ActionMailer config from CoTech Cobudget ('Enable Start TLS Auto', 'SSL' and 'TLS')

    This results in an SSL error.
    # ActionMailer config

    ```
    config.action_mailer.smtp_settings = {
    address: 'email-smtp.eu-west-1.amazonaws.com',
    port: 25,
    enable_starttls_auto: true,
    tls: true,
    ssl: true,
    port: 25, # or 465 or 587
    enable_starttls_auto: <boolean>,
    tls: <boolean>,
    ssl: <boolean>,
    user_name: '<username>',
    password: '<password>'
    }
    ```

    ```
    $ rails c
    > UserMailer.with({}).welcome_email.deliver_now
    OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
    ```

    # Using 'Enable Start TLS Auto' and 'TLS'

    This results in an SSL error.

    ```
    config.action_mailer.smtp_settings = {
    address: 'email-smtp.eu-west-1.amazonaws.com',
    port: 25,
    enable_starttls_auto: true,
    tls: true,
    user_name: '<username>',
    password: '<password>'
    }
    ```
    ## Test command

    ```
    $ rails c
    > UserMailer.with({}).welcome_email.deliver_now
    > OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
    $ rails r "UserMailer.with({}).welcome_email.deliver_now"
    ```

    # Using 'Enable Start TLS Auto' and 'SSL'

    This results in an SSL error.
    ## Results

    ```
    config.action_mailer.smtp_settings = {
    address: 'email-smtp.eu-west-1.amazonaws.com',
    port: 25,
    enable_starttls_auto: true,
    ssl: true,
    user_name: '<username>',
    password: '<password>'
    }
    ```
    In summary:

    ```
    $ rails c
    > UserMailer.with({}).welcome_email.deliver_now
    > OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
    ```
    Ports 25 and 587 require `enable_starttls_auto` to be set to `true`, and for `tls` and `ssl` to be set to `false`.

    # Using 'Enable Start TLS Auto'
    Port 465 ignores `enable_starttls_auto` and requires either `tls` or `ssl` to be set to `true`.

    This works correctly. And presumably encrypts the traffic.

    ```
    config.action_mailer.smtp_settings = {
    address: 'email-smtp.eu-west-1.amazonaws.com',
    port: 25,
    enable_starttls_auto: true,
    user_name: '<username>',
    password: '<password>'
    }
    ```

    ```
    $ rails c
    > UserMailer.with({}).welcome_email.deliver_now
    # No errors and the email is sent correctly.
    ```

    # Using none of 'Enable Start TLS Auto', 'SSL' or 'TLS'

    ```
    config.action_mailer.smtp_settings = {
    address: 'email-smtp.eu-west-1.amazonaws.com',
    port: 25,
    enable_starttls_auto: false,
    user_name: '<username>',
    password: '<password>'
    }
    ```

    ```
    $ rails c
    > UserMailer.with({}).welcome_email.deliver_now
    Net::SMTPAuthenticationError: 530 Must issue a STARTTLS command first
    ```
    | Port | Enable StartTLS Auto | TLS | SSL | Outcome |
    | 25 | True | True | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 25 | True | True | False | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 25 | True | False | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 25 | True | False | False | Email sent correctly |
    | 25 | False | False | False | Net::SMTPAuthenticationError: 530 Must issue a STARTTLS command first |
    | 25 | False | True | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 25 | False | True | False | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 25 | False | False | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 465 | True | True | True | Email sent correctly |
    | 465 | True | True | False | Email sent correctly |
    | 465 | True | False | True | Email sent correctly |
    | 465 | True | False | False | Net::ReadTimeout: Net::ReadTimeout |
    | 465 | False | False | False | Net::ReadTimeout: Net::ReadTimeout |
    | 465 | False | True | True | Email sent correctly |
    | 465 | False | True | False | Email sent correctly |
    | 465 | False | False | True | Email sent correctly |
    | 587 | True | True | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 587 | True | True | False | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 587 | True | False | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 587 | True | False | False | Email sent correctly |
    | 587 | False | False | False | Net::SMTPAuthenticationError: 530 Must issue a STARTTLS command first |
    | 587 | False | True | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 587 | False | True | False | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
    | 587 | False | False | True | OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol |
  6. chrisroos revised this gist Apr 30, 2018. 1 changed file with 24 additions and 0 deletions.
    24 changes: 24 additions & 0 deletions 2018-04-30-rails-and-aws-ses.md
    Original file line number Diff line number Diff line change
    @@ -89,3 +89,27 @@ config.action_mailer.smtp_settings = {
    password: '<password>'
    }
    ```

    ```
    $ rails c
    > UserMailer.with({}).welcome_email.deliver_now
    # No errors and the email is sent correctly.
    ```

    # Using none of 'Enable Start TLS Auto', 'SSL' or 'TLS'

    ```
    config.action_mailer.smtp_settings = {
    address: 'email-smtp.eu-west-1.amazonaws.com',
    port: 25,
    enable_starttls_auto: false,
    user_name: '<username>',
    password: '<password>'
    }
    ```

    ```
    $ rails c
    > UserMailer.with({}).welcome_email.deliver_now
    Net::SMTPAuthenticationError: 530 Must issue a STARTTLS command first
    ```
  7. chrisroos created this gist Apr 30, 2018.
    91 changes: 91 additions & 0 deletions 2018-04-30-rails-and-aws-ses.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,91 @@
    I added two verified email addresses to SES so that I could send emails from/to them while in the SES Sandbox.

    # UserMailer

    ```
    class UserMailer < ApplicationMailer
    default from: 'accounts+aws-ses@gofreerange.com'
    def welcome_email
    mail(to: 'chris.roos@gofreerange.com', subject: 'Welcome to My Awesome Site')
    end
    end
    ```

    # Using ActionMailer config from CoTech Cobudget ('Enable Start TLS Auto', 'SSL' and 'TLS')

    This results in an SSL error.

    ```
    config.action_mailer.smtp_settings = {
    address: 'email-smtp.eu-west-1.amazonaws.com',
    port: 25,
    enable_starttls_auto: true,
    tls: true,
    ssl: true,
    user_name: '<username>',
    password: '<password>'
    }
    ```

    ```
    $ rails c
    > UserMailer.with({}).welcome_email.deliver_now
    OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
    ```

    # Using 'Enable Start TLS Auto' and 'TLS'

    This results in an SSL error.

    ```
    config.action_mailer.smtp_settings = {
    address: 'email-smtp.eu-west-1.amazonaws.com',
    port: 25,
    enable_starttls_auto: true,
    tls: true,
    user_name: '<username>',
    password: '<password>'
    }
    ```

    ```
    $ rails c
    > UserMailer.with({}).welcome_email.deliver_now
    > OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
    ```

    # Using 'Enable Start TLS Auto' and 'SSL'

    This results in an SSL error.

    ```
    config.action_mailer.smtp_settings = {
    address: 'email-smtp.eu-west-1.amazonaws.com',
    port: 25,
    enable_starttls_auto: true,
    ssl: true,
    user_name: '<username>',
    password: '<password>'
    }
    ```

    ```
    $ rails c
    > UserMailer.with({}).welcome_email.deliver_now
    > OpenSSL::SSL::SSLError: SSL_connect returned=1 errno=0 state=SSLv2/v3 read server hello A: unknown protocol
    ```

    # Using 'Enable Start TLS Auto'

    This works correctly. And presumably encrypts the traffic.

    ```
    config.action_mailer.smtp_settings = {
    address: 'email-smtp.eu-west-1.amazonaws.com',
    port: 25,
    enable_starttls_auto: true,
    user_name: '<username>',
    password: '<password>'
    }
    ```