首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >发送模板邮件时SendGrid返回错误

发送模板邮件时SendGrid返回错误
EN

Stack Overflow用户
提问于 2020-03-27 18:40:19
回答 1查看 34关注 0票数 0

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

代码语言:javascript
复制
 config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
 config.action_mailer.asset_host = 'http://localhost:3000'

你知道它为什么返回这个错误吗?我已经浏览了gem文档,但是找不到任何关于这个错误的东西。

我使用的是带有ruby 2.6.5的Rails5。

EN

回答 1

Stack Overflow用户

发布于 2020-03-27 19:48:33

在我的例子中,我在config/environments/[xxx].rb中像这样实现了它

代码语言:javascript
复制
  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"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60884347

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档