为什么我不能通过邮戳发送电子邮件?

时间:2016-09-22 14:12:27

标签: ruby-on-rails actionmailer postmark

我已在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 方法的正确方法是什么?

rails server write:

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'

0 个答案:

没有答案