0

I've created a service on postmarkapp.com and checked it with:

 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.'}"

This works fine.

To send mail from my Rails application, I've written:

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

In application.rb:

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

This doesn't work. What's the proper way to call the .message method?

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'
Vladimir
  • 67
  • 5

0 Answers0