0

我已经创建了一项服务postmarkapp.com并通过以下方式对其进行了检查:

 curl "https://api.postmarkapp.com/email" \
  -X POST \
  -H "Accept: application/json" \
  -H "Content-Type: application/json" \
  -H "X-Postmark-Server-Token: my token" \
  -d "{From: 'test@mydomen.tk', To: 'testemail@example.com', Subject: 'Hello from Postmark', HtmlBody: '<strong>Hello</strong> dear Postmark user.'}"

这工作正常。

为了从我的 Rails 应用程序发送邮件,我写了:

class UserMailer < ApplicationMailer
  def message
    mail(
      :subject => 'Hello from Postmark',
      :to  => 'testemail@example.com',
      :from => 'test@mydomen.tk',
      :html_body => '<strong>Hello</strong> dear Postmark user!!!.',
      :track_opens => 'true')
  end
end

class UsersController < ApplicationController
  def create
    @user = User.new(user_params)

    respond_to do |format|
      if @user.save
        #I try send message
        UserMailer.message.deliver_now  # It doesn't work

        format.html { redirect_to @user, notice: 'User was successfully created.' }
        format.json { render :show, status: :created, location: @user }
      else
        format.html { render :new }
        format.json { render json: @user.errors, status: :unprocessable_entity }
      end
    end
  end

application.rb

class Application < Rails::Application
    #postmark_settings
    config.action_mailer.delivery_method = :postmark
    config.action_mailer.postmark_settings = { :api_token => "my_token" }
end

这行不通。调用.message方法的正确方法是什么?

导轨服务器写:

app/mailers/user_mailer.rb:4:in `message'
  app/mailers/user_mailer.rb:4:in `message'
  app/mailers/user_mailer.rb:4:in `message'
  app/mailers/user_mailer.rb:4:in `message'
  app/mailers/user_mailer.rb:4:in `message'
  app/controllers/users_controller.rb:32:in `block in create'
  app/controllers/users_controller.rb:29:in `create'
4

0 回答 0