我正在使用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文档,但是找不到任何关于这个错误的东西。
我使用的是带有ruby 2.6.5的Rails5。
发布于 2020-03-27 19:48:33
在我的例子中,我在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"https://stackoverflow.com/questions/60884347
复制相似问题