我在 Ruby 和 Rails 框架上使用 SendGrid 邮件程序。在密码重置电子邮件模板中,我们发送一个密码重置链接,其格式如下(https://subdomain.domainname.com/password_reset/token/?some_other_params https://subdomain.domainname.com/password_reset/token/?some_other_params)。大多数情况下,密码重置链接会以正确的格式通过电子邮件发送给收件人,但对于某些客户来说,它不会发送正确的链接。我们注意到的问题是“(子域名和域名)或(域名和 com)之间随机缺少点,并且生成的给客户的密码重置链接看起来像(https://subdomaindomainname.com/password_reset/token/?some_other_params https://subdomaindomainname.com/password_reset/token/?some_other_params)这是一个错误的链接。此问题仅在生产中发生并且非常随机。
我验证了源代码中包含域名的变量,并验证了生成 url 的代码,并对此进行了彻底测试,它们在我们的源代码中没有问题。在谷歌上我看到this https://stackoverflow.com/questions/31227537/dot-s-are-missing-here-there-in-the-mail-html-while-sending-pear-mail-mime-e问题。我不明白如何在 SendGrid 电子邮件客户端上以编程方式解决此问题。
邮件程序.rb
class Mailer < ActionMailer::Base
sendgrid_category Rails.env
default_url_options[:host] = APP_URL
end
配置/环境/生产.rb
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.sendgrid.net",
:user_name => ENV['SENDGRID_USERNAME'],
:password => ENV['SENDGRID_PASSWORD'],
:domain => "subdomain.domainname.com",
:port => 587,
:authentication => "plain",
:enable_starttls_auto => true
}
APP_URL = "subdomain.domainname.com"
mailer_helper.rb
def link_to_with_ga(*args)
args[1] = append_ga args[1], 'html'
link_to *args
end
def append_ga(link, utm_content)
link << "#{link.include?('?') ? '&' : '?' }#{@ga_tag}&utm_content=#{utm_content}"
end
_reset_password_view.rb
<%= link_to_with_ga(t("users.reset_password"), reset_password_url(:token => @token, :locale=>@user_locale,:protocol => ( Rails.env.eql?('development') ? 'http' : 'https' )),:id => 'reset_link') %>
请帮我解决这个问题。
谢谢