actionmailer

rails mailer with different layouts

喜夏-厌秋 提交于 2020-01-01 09:32:31
问题 I use one layout for all my emails in my Notifier model (20+ emails)... however sometimes I just want to send a plain text email with no layout or html at all. I can't seem to be able to figure out how? If I try to send a plain text email i still get the layout, and all the HTML in the email. I'm using Rails 2.3.8. I read about this monkey patch here... but it seemed to indicate a newer version of rails had over come this? And I don't really wanna monkey patch if I can avoid one. Rails -

In Rails why is my mail body empty only in my test?

我的梦境 提交于 2020-01-01 07:57:06
问题 I have an actionmailer class and associated overhead, it works perfectly. In my unit test (rails default minitest) however, the email body is empty. Why is that? my mailer class: class TermsMailer < ApplicationMailer default from: "info@domain.com" def notice_email(user,filename) @user = user @file = filename mail(to: "info@domain.com", subject: 'Data downloaded') end end my test: require 'test_helper' class TermsMailerTest < ActionMailer::TestCase test "notice" do email = TermsMailer.notice

Rails 4, Mailer preview, preview attached images

半城伤御伤魂 提交于 2020-01-01 05:11:26
问题 I have problem with rails 4.1.6 mailer preview. I want to see attached images in preview mode, but it doesn't work. I think it's incorrect There is my code: Mailer file class AppMailer < ActionMailer::Base default from: "robot@mysite.com" # AppMailer.test_mail.deliver def test_mail attachments.inline['rails.png'] = File.read(Rails.root.join('app', 'assets', 'images', 'rails.png')) mail( to: 'my-email@gmail.com', subject: "test letter", template_path: "mailers", template_name: "test" ) end end

How to make Delayed_Job notify Airbrake when an ActionMailer runs into an error?

假如想象 提交于 2020-01-01 04:23:08
问题 The DelayedJob docs mention hooks, including an error hook, but only in the context of custom Job subclasses. This similar question (with no answers) says adding the same hook to the mailer class did not work. What's the trick? Update: In general, I'd like to see how to add hooks to jobs that are triggered using the object.delay.action() syntax, where I don't see an obvious link to a ____Job class. 回答1: I was just searching for a solution to this problem too, and I found this gist. I don't

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-31 10:04:10
问题 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 =>

Single quote string string interpolation

十年热恋 提交于 2019-12-30 09:07:28
问题 I am trying to set an email address within ActionMailer with Rails. Before it was hard coded, but we want to make them ENV variables now so we don't need to amend code each time an email changes. Here is how it's currently defined: from = '"Name of Person" <email@email.com>' I've tried setting the email as an environment variable using ENV['EMAIL'] but I'm having no luck even with #{ENV['EMAIL'} . Can anyone point me in the right direction? 回答1: You cannot use string interpolation with single

CSS Images in Email With Rails 3

喜夏-厌秋 提交于 2019-12-30 05:12:27
问题 I'm trying to send out an email with Rails 3 and Action Mailer. The email goes out fine, but I want it to be HTML formatted with some basic styling which includes background images. I understand that the images might get blocked until the user allows them to be shown, but I still think it would be best to link to the images on my web server. The email template called registration_confirmation.html.erb starts out like this: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/

Rails 3 + action mailer - Cannot loop to send emails

拜拜、爱过 提交于 2019-12-30 00:50:29
问题 A user can create an object, and he has followers that I want to alert when he creates this object. controller: if @project.save format.html { redirect_to(@project, :notice => 'Project was successfully created.') } format.xml { render :xml => @project, :status => :created, :location => @project } # Send a notification to project owner's followers : UserMailer.new_project(@project).deliver else ... user_mailer.rb: def new_project(project) @url = "http://localhost:3000/" @project = project #

Mailer unable to access reset_token in User model

懵懂的女人 提交于 2019-12-29 09:12:00
问题 faced with an issue where @user.reset_token returns nil. app/views/user_mailer/password_reset.html.erb <%= link_to "Reset password", edit_password_reset_url(@user.reset_token, email: @user.email) %> Reset_token is declared in User model, whereby this problem happens when I try to use a sidekiq worker. Refer to code below. app/models/user.rb class User < ActiveRecord::Base attr_accessor :reset_token def User.new_token SecureRandom.urlsafe_base64 end def send_password_reset_email

ActionMailer: Default From: address?

为君一笑 提交于 2019-12-29 04:36:48
问题 Googled for this to no avail. Didn't find anything in the API either. I was expecting some kind of class method or configuration option to set it... So, rather than calling from "my@email.com" for every method, it could be called automatically. 回答1: Rails 3 config/environments/development.rb: ActionMailer::Base.default :from => 'default@development-server.com' config/environments/production.rb: ActionMailer::Base.default :from => 'default@production-server.com' You can also set this per