rails postmark_mailer 不起作用。我缺少模板 ID (APInputError),当我使用默认模板时它可以工作

问题描述 投票:0回答:1

我想向我的应用程序的新用户发送一封欢迎电子邮件。如果我使用默认的,它可以工作,但是当我编辑电子邮件布局时,我收到 API 错误。未找到或丢失与此请求关联的 TemplateID。

我严格遵循 gem 文档https://github.com/scienceexchange/postmark_mailer

我的代码如下所示:

class UserMailer < PostmarkMailer::Base
 def welcome_email(user)
  @user = user
  @url  = 'http://listy.club/users/sign_in'
  mail(
  to: @user.email,
  from:'[email protected]',
  template_id: 8043061,
  template_model: {
    username: @user.username,
    company_name: "Listy",
    product_name: "Listy",
    action_url: "http://www.listy.club/users/sign_in",
    login_url: "http://www.listy.club/users/sign_in",
    support_email: "[email protected]",
    help_url: "help_url_Value",
    company_address: "Germany 10439 Berlin"
   }
  )
 end
end

PostmarkMailer.configure do |config|
config.api_key = "ce14d1d0-****-***-****-****cf08e3e" # required
config.default_delivery_queue = :mailers # defaults to :default
end

有人看到这里有错误吗?将不胜感激!

ruby-on-rails rubygems
1个回答
0
投票

这适用于新的邮戳 gem 版本。

您必须将模板命名为与操作名称相同的名称。所以在这种情况下,你必须将你的模板命名为=welcome。

class EmailMailer < ApplicationMailer
  include PostmarkRails::TemplatedMailerMixin

  default from: "[email protected]", message_stream: 'broadcast'

  def welcome
    @user = params[:user]

    self.template_model = { action_url: "https://www.example.com/" }
    mail( to: @user.email )
  end

end
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.