Skip to content

Instantly share code, notes, and snippets.

@alexeevit
Forked from the-teacher/app.md
Last active December 5, 2019 06:45
Show Gist options
  • Save alexeevit/496f5634f910d5be80e386cee422e040 to your computer and use it in GitHub Desktop.
Save alexeevit/496f5634f910d5be80e386cee422e040 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

  sendmail:
    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 == 'sendmail'
      config.action_mailer.raise_delivery_errors = true

      config.action_mailer.sendmail_settings = {
        location:  Settings.mailer.sendmail.location,
        arguments: Settings.mailer.sendmail.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