[发送模板电子邮件时,SendGrid返回错误

问题描述 投票:0回答:1

我正在使用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)

我的development.rb:

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

知道为什么会返回此错误吗?我已经看过gem文档,但找不到与此错误有关的任何信息。

我正在将Rails 5与ruby 2.6.5一起使用。

ruby-on-rails ruby-on-rails-5 sendgrid sendgrid-api-v3 sendgrid-rails
1个回答
0
投票

就我而言,我在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"
© www.soinside.com 2019 - 2024. All rights reserved.