Ошибка отправки SendGrid при отправке шаблона электронной почты - PullRequest
0 голосов
/ 27 марта 2020

Я использую sendgrid- ruby gem для отправки шаблона электронной почты, но он возвращает ошибку:

Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

Мой код выглядит следующим образом: @sendgrid = SendGrid::API.new(api_key: 'api_key', host: 'localhost') result = @sendgrid.client.mail._('send').post(request_body: template)

My development.rb:

 config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
 config.action_mailer.asset_host = 'http://localhost:3000'

Есть идеи, почему он возвращает эту ошибку? Я прошел через документацию по драгоценным камням, но не могу найти что-либо об этой ошибке.

Я использую рельсы 5 с ruby 2.6.5.

1 Ответ

0 голосов
/ 27 марта 2020

В моем случае я реализовал это так: config/environments/[xxx].rb:

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.default_url_options = { host: 'https://portal.com.br' }
  # Sendgrid port configuration
  config.action_mailer.smtp_settings = {
      :address              => 'smtp.sendgrid.net',
      :port                 => '587',
      :authentication       => :plain,
      :domain               => 'xxx.com.br',
      :user_name            => 'solutions',
      :password             => 'dns232323',
      :enable_starttls_auto => true
  }

  Rails.application.routes.default_url_options[:protocol] = "https"
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...