繁体   English   中英

在没有模板的情况下发送 Sendgrid 电子邮件

[英]Sendgrid emails being sent without the template

我的 sendgrid 电子邮件发送正常,但从未加载模板。 我已经多次尝试使用许多模板,但从未调用过它们,所以我的调用一定有问题。

这是来自 controller 的电话:

AdminMailer.with( email: "xxxxxxxxx@gmail.com" , id:item.id, name: item.name, room: item.room.name).send_stock.deliver_later

这是我的 admin_mailer.rb

class AdminMailer < ApplicationMailer
  def send_stock
    mail(to: params[:email],
      subject: 'Foto sin inventario',
      body: 'email body',
      delivery_method_options: {
        api_key: ENV["SENDGRID_API"]
      },
      template_id: 'd-2d99d960ed47490497f1a99af32cd706', 
      dynamic_template_data:{
        'id': params[:id],
        'name': params[:name],
        'room': params[:room]
      }
    )
  end 

这是来自 rails 的 output:

[ActiveJob] [ActionMailer::MailDeliveryJob] [d8927648-36ca-4e60-afd3-7fe6ea1b936f] Performing ActionMailer::MailDeliveryJob (Job ID: d8927648-36ca-4e60-afd3-7fe6ea1b936f) from Async(mailers) enqueued at 2022-09-29T22:08:22Z with arguments: "AdminMailer", "send_stock", "deliver_now", {:params=>{:email=>"xxxxxxxxx@gmail.com", :id=>4, :name=>"foto 3 exclusive", :room=>"Sala 1"}, :args=>[]}
[ActiveJob] [ActionMailer::MailDeliveryJob] [d8927648-36ca-4e60-afd3-7fe6ea1b936f] AdminMailer#send_stock: processed outbound mail in 1.0ms
[ActiveJob] [ActionMailer::MailDeliveryJob] [d8927648-36ca-4e60-afd3-7fe6ea1b936f] Delivered mail 6336175785e4_366932af97af0d39c27826@miguel.mail (7142.5ms)
[ActiveJob] [ActionMailer::MailDeliveryJob] [d8927648-36ca-4e60-afd3-7fe6ea1b936f] Date: Thu, 29 Sep 2022 17:08:23 -0500
From: xxxxxxxxx@gmail.com
To: xxxxxxxxx@gmail.com
Message-ID: <6336175785e4_366932af97af0d39c27826@miguel.mail>
Subject: Foto sin inventario
Mime-Version: 1.0
Content-Type: text/plain;
 charset=UTF-8
Content-Transfer-Encoding: 7bit
template-id: d-2d99d960ed47490497f1a99af32cd706
dynamic-template-data: {:id=>4, :name=>"foto 3 exclusive", :room=>"Sala 1"}

email body
[ActiveJob] [ActionMailer::MailDeliveryJob] [d8927648-36ca-4e60-afd3-7fe6ea1b936f] Performed ActionMailer::MailDeliveryJob (Job ID: d8927648-36ca-4e60-afd3-7fe6ea1b936f) from Async(mailers) in 7150.18ms

找不到很多关于模板问题的文档。

问题是您为这个 function 调用提供了 body 属性,它告诉 SDK 你想用这个主体发送一个 email。 如果要使用模板,则需要省略此属性。

至少,这就是它在 node.js SDK 中的工作方式,根据这个示例代码,我假设 Ruby 的工作方式类似。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM