actionmailer

Save each email before sending rails 4

好久不见. 提交于 2019-12-03 08:34:04
I want to keep track of all triggered emails by the application into a db table, so that i can have a log which emails are sent and to whom. Kindly suggest me the best possible solution. I have solved this using the following way: created a class in lib directory class MyProjectMailLogger def self.delivering_email(message) @to = message.to.to_s @subject = message.subject.to_s @message = message.body.to_s EmailQueue.create!(:receipient_email => @to, :subject => @subject, :message => @message, :email_status_id => 3) end end In config/initalizers/setup_mail.rb ActionMailer::Base.register

Testing ActionMailer multipart emails with RSpec

浪尽此生 提交于 2019-12-03 02:42:01
问题 I'm currently testing my mailers with RSpec, but I've started setting up multipart emails as described in the Rails Guides here: http://guides.rubyonrails.org/action_mailer_basics.html#sending-multipart-emails I have both mailer templates in text and html formats, but it looks like my tests are only checking the HTML portion. Is there a way to check the text template separately? Is it only checking the HTML view because it's first in the default order? 回答1: To supplement, nilmethod's

How do I get full URL to an image in a Rails asynchronous mailer?

心已入冬 提交于 2019-12-03 01:23:50
I want to have emails I send out with ActionMailer contain images that link back to my app. In my development environment, for example: <img src="http://myfullappurl.dev/assets/myimage.png"> I have this in my development.rb config.action_controller.asset_host = 'myfullappurl.dev' config.action_mailer.asset_host = config.action_controller.asset_host config.action_mailer.default_url_options = { host: 'myfullappurl.dev', only_path: false } But I can not get my mail templates to render a full URL in any of these way: asset_path('myimage.png') asset_path('myimage.png', only_path: false) image_url(

Render Different View (template) for ActionMailer

霸气de小男生 提交于 2019-12-03 01:03:33
I'm trying to do a conditional render of a different template from ActionMailer (Rails 3.1.1). I want most users to get the normal welcome.html.erb template, but some users to get the special welcome_photographer.html.erb template. This type of thing works in ActionController: # (in /app/mailers/user_mailer.rb) def welcome(user) @user = user mail(:to => "#{@user.name} <#{@user.email}>", :subject => "Welcome to ...") render "welcome_photographer" if @user.is_photographer end But the render doesn't work -- everyone gets the standard welcome.html.erb even if @user.is_photographer == true Sean

ActionView::Template::Error: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true

我的未来我决定 提交于 2019-12-02 19:00:15
My ruby on rails action mailer runs all good in development environment, but in production environment, it keeps throw: ActionView::Template::Error: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true My development config is config.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :port => xxx, :address => 'smtp.example.org', :user_name => 'xxx@example.com', :password => 'xxxxxxxx', :domain => 'xxxxxx.com', :authentication => :plain, } config.action_mailer.default_url_options = { :host => 'localhost

ActionMailer testing with rspec [closed]

无人久伴 提交于 2019-12-02 17:56:09
I am developing a Rails 4 application which involves sending / receiving emails. For example, I send emails during user registration, user comment, and other events in the app. I have created all emails using the action mailer , and I used rspec and shoulda for testing. I need to test if the mails are received correctly to the proper users. I don't know how to test the behavior. Please show me how to test an ActionMailer using shoulda and rspec . CDub How to test ActionMailer with RSpec works for Rails 3 and 4 this information has been taken from a good tutorial Assuming the following Notifier

Testing ActionMailer multipart emails with RSpec

↘锁芯ラ 提交于 2019-12-02 16:15:49
I'm currently testing my mailers with RSpec, but I've started setting up multipart emails as described in the Rails Guides here: http://guides.rubyonrails.org/action_mailer_basics.html#sending-multipart-emails I have both mailer templates in text and html formats, but it looks like my tests are only checking the HTML portion. Is there a way to check the text template separately? Is it only checking the HTML view because it's first in the default order? To supplement, nilmethod's excellent answer, you can clean up your specs by testing both text and html versions using a shared example group:

Net::SMTPAuthenticationError 502 5.5.2 in Rails ActionMailer

我只是一个虾纸丫 提交于 2019-12-02 04:39:59
问题 i'm trying to send confirmation email to the user. But i get following error: Net::SMTPAuthenticationError (502 5.5.2 Error: command not recognized Configuration in production.rb is following: # Disable delivery errors, bad email addresses will be ignored config.action_mailer.raise_delivery_errors = true # set delivery method to :smtp, :sendmail or :test config.action_mailer.delivery_method = :smtp # these options are only needed if you choose smtp delivery config.action_mailer.smtp_settings

Delayed Jobs and Action Mailer

冷暖自知 提交于 2019-12-01 21:18:52
问题 I am having trouble with implementing delayed jobs with my ActionMailer: Before Delayed Job Implementation: class NotificationsMailer < ActionMailer::Base default :from => "noreply@mycompany.com" default :to => "info@mycompany.com" def new_message(message) @message = message mail(:subject => "[Company Notification] #{message.subject}") end end and called it using this line (it worked perfectly fine): NotificationsMailer.new_message(@message).deliver After the Delayed Job implementation all i

How to send an email with rails

天涯浪子 提交于 2019-12-01 20:47:51
问题 This is probably very straight forward and simple, but I'm very new and noob at ruby on rails. I have a simple email php script that I used on an older website, but now since I've converted to rails I'm not sure as to how to create the equivalent to that. I tried using rails generate mailer Notifier and then inside of that added a welcome method which sent and email. However in the User controller (under create so that when a user made an account their email address was sent a welcome email)