我正在使用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一起使用。
就我而言,我在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"