Skip to content

Instantly share code, notes, and snippets.

@the-teacher
Last active November 21, 2020 19:14
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save the-teacher/6dfe0b2050dfa7092ccd to your computer and use it in GitHub Desktop.
Save the-teacher/6dfe0b2050dfa7092ccd to your computer and use it in GitHub Desktop.
Rails Mailer Yandex

Gemfile

gem 'rails_config'

config/settings/development.yml

mailer:
  service: smtp
  host: localhost:3000

  sandmail:
    location:  '/usr/sbin/sendmail'
    arguments: '-i -t'

  smtp:
    address: 'smtp.yandex.ru'
    domain:  'yandex.ru'
    port:    25

    email:   'robot@my-site.ru'
    password: QWERTY_PASSWORD
    authentication: plain

config/application.rb

    # ======================================================
    #  Mailer settings
    # ======================================================
    config.action_mailer.default_url_options = { host: Settings.mailer.host }

    if Settings.mailer.service == 'smtp'
      config.action_mailer.delivery_method = :smtp
      config.action_mailer.raise_delivery_errors = true

      config.action_mailer.smtp_settings = {
        address: Settings.mailer.smtp.address,
        domain:  Settings.mailer.smtp.domain,
        port:    Settings.mailer.smtp.port,

        user_name: Settings.mailer.smtp.email,
        password:  Settings.mailer.smtp.password,

        authentication: Settings.mailer.smtp.authentication,
        enable_starttls_auto: true
      }
    elsif Settings.mailer.service == 'sandmail'
      config.action_mailer.raise_delivery_errors = true

      config.action_mailer.sendmail_settings = {
        location:  Settings.mailer.sandmail.location,
        arguments: Settings.mailer.sandmail.arguments
      }
    else
      config.action_mailer.delivery_method = :test
      config.action_mailer.raise_delivery_errors = false
    end
    # ======================================================
    #  ~ Mailer settings
    # ======================================================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment