ruby-on-rails – 如何使用ruby on rails在sendgrid中动态设置取消订阅链接

ruby-on-rails – 如何使用ruby on rails在sendgrid中动态设置取消订阅链接,第1张

概述我正在使用sendgrid发送邮件.大约有20个邮件模板. 我在sendgrid应用程序“订阅跟踪”的设置中设置了取消订阅模板. 我的要求是针对不同邮件模板的取消订阅链接的不同文本. 目前,只有一个静态取消订阅链接在sendgrid应用程序“订阅跟踪”中设置即将到来. 任何人都可以帮助我如何在我的user_mailer类中动态设置取消订阅链接. 我按照这个链接To give unsubscribe 我正在使用sendgrID@R_403_6115@.大约有20个邮件模板.

我在sendgrID应用程序“订阅跟踪”的设置中设置了取消订阅模板.

我的要求是针对不同邮件模板的取消订阅链接的不同文本.

目前,只有一个静态取消订阅链接在sendgrID应用程序“订阅跟踪”中设置即将到来.

任何人都可以帮助我如何在我的user_mailer类中动态设置取消订阅链接.

我按照这个链接To give unsubscribe link in the mail using sendgrid XSMTPAPI header.但我不知道如何在ruby中实现它.

下面是我在user_mailer类中尝试过的代码.

def abuse_notification(post,current_user,eventID)     headers['X-SMTPAPI'] = '{"filters":{"subscriptiontrack":{"settings":{"enable":1,"text/HTML":"Unsubscribe <%Here%>","text/plain":"Unsubscribe Here: <% %>"}}}}'.to_Json()  UserNotifIEr.smtp_settings.merge!({:user_name => "info@xxxx.example.com"})    @recipIEnts  = "test@xxx.example.com"    @from        = "xxxx"    @subject     = "Report Abuse Notification"    @sent_on     = Time.Now    @body[:user] = current_user    @body[:event] = post  end
解决方法 您在正确的轨道上,但要使用SendGrID SMTP API,您将为每封电子邮件添加标题,而不是添加到您的设置.在SMTP设置中,您将进一步存储(至少)user_name,密码,地址,SendGrid Docs,详细配置.使用ActionMailer,您可以按如下方式配置它:

ActionMailer::Base.smtp_settings = {  :user_name => 'sendgrIDusername',:password => 'sendgrIDpassword',:domain => 'yourdomain.com',:address => 'smtp.sendgrID.net',:port => 587,:authentication => :plain,:enable_starttls_auto => true}

配置ActionMailer后,您需要设置UserNotifIEr类以查找类似于以下内容的内容.每个单独的方法将设置X-SMTPAPI标头:

class UserNotifIEr < ActionMailer::Base  default :from => "bob@example.com"  def send_message(name,email,message)    @name = name    @email = email    @message = message    headers['X-SMTPAPI'] = '{"filters":{"subscriptiontrack":{"settings":{"enable":1,"text/plain":"Unsubscribe Here: <% %>"}}}}'    mail(      :to => 'george@example.com',:from => email,:subject => 'Example Message'    )  endend

请注意,X-SMTPAPI标头是JsON,如果您希望将Ruby对象转换为JsON,则需要使用JsON gem.

总结

以上是内存溢出为你收集整理的ruby-on-rails – 如何使用ruby on rails在sendgrid中动态设置取消订阅链接全部内容,希望文章能够帮你解决ruby-on-rails – 如何使用ruby on rails在sendgrid中动态设置取消订阅链接所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1290571.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存