actionmailer

Rails 3 -Render PDF from view and attach to email

我只是一个虾纸丫 提交于 2019-11-30 03:12:34
I have been using Wicked_pdf to render a view as a PDF and actionmailer to send emails, but I can't get them to work together. I want to attach a PDF version of a certain view to an email using actionmailer and send it out by clicking a link or a button. I have a link_to command that sends out an email. Here is my controller that gets the email generated: def sendemail @user = User.find(params[:id]) Sendpdf.send_report(@user).deliver redirect_to user_path(@user) flash[:notice] = 'Email has been sent!' end Here is what I have in my actionmailer: class Sendpdf < ActionMailer::Base default :from

How do I create email with css and images from Rails?

不羁的心 提交于 2019-11-30 00:04:32
How do you create and send emails from Rails application, that contain images and proper formatting? like the ones you get from facebook and like. Bo Jeanes Assuming you know how to send normal plain-text emails from Rails using ActionMailer, to get HTML emails working you need to set a content type for your email. For example, your notifer might look like this: class MyMailer < ActionMailer::Base def signup_notification(recipient) recipients recipient.email_address_with_name subject "New account information" from "system@example.com" body :user => recipient content_type "text/html" end end

Rails - How do you test ActionMailer sent a specific email in tests

泄露秘密 提交于 2019-11-29 20:45:41
Currently in my tests I do something like this to test if an email is queued to be sent assert_difference('ActionMailer::Base.deliveries.size', 1) do get :create_from_spreedly, {:user_id => @logged_in_user.id} end but if i a controller action can send two different emails i.e. one to the user if sign up goes fine or a notification to admin if something went wrong - how can i test which one actually got sent. The code above would pass regardless. When using the ActionMailer during tests, all mails are put in a big array called deliveries . What you basically are doing (and is sufficient mostly)

Rails - Mail, getting the body as Plain Text

倾然丶 夕夏残阳落幕 提交于 2019-11-29 20:15:37
Given: message = Mail.new(params[:message]) as seen here: http://docs.heroku.com/cloudmailin It shows how to get the message.body as HTML, how to do you get the plain/text version? Thanks The code above: message = Mail.new(params[:message]) will create a new instance of the mail gem from the full message. You can then use any of the methods on that message to get the content. You can therefore get the plain content using: message.text_part or the HTML with message.html_part These methods will just guess and find the first part in a multipart message of either text/plain or text/html content

How to render rails mailer views in Mailgun HTTP API

天大地大妈咪最大 提交于 2019-11-29 19:12:32
问题 I'm using Mailgun HTTP API to send emails from rails application.But I'm not able to render the mailer views. This is my mailer class. class MailgunMails < ActionMailer::Base def send_complex_message data = Multimap.new data[:from] = "Excited User <postmasters@#{@@domain}>" data[:to] = "alice@example.com" data[:subject] = "Hello" data[:html] = File.open("#{Rails.root}/app/views/mailgun_mails/send_complex_message.html.erb", 'r').to_s.html_safe ## also tried data[:html] = render(template: "send

Mailer unable to access reset_token in User model

懵懂的女人 提交于 2019-11-29 16:16:53
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 PasswordResetWorker.perform_async(self.id) end private def create_reset_digest self.reset_token = User.new_token

ActionMailer and Ramaze

独自空忆成欢 提交于 2019-11-29 11:01:23
Is it possible to use ActionMailer in a web framework like Ramaze, or do I need to use Rails? You can use ActionMailer without Rails quite easily. I'm not familiar with Ramaze, but here's plain ruby, which should be easy to integrate into whatever framework you wish: PATH/mailer.rb require 'rubygems' require 'action_mailer' class Mailer < ActionMailer::Base def my_email recipients "recipient@their_domain.com" from "me@my_domain.com" subject "my subject" body :variable1 => 'a', :variable2 => 'b' end end Mailer.template_root = File.dirname(__FILE__) Mailer.delivery_method = :sendmail Mailer

Rails and Gmail SMTP, how to use a custom from address

冷暖自知 提交于 2019-11-29 10:49:10
I've got my Rails (2.1) app setup to send email via Gmail, however whenever I send an email no matter what I set the from address to in my ActionMailer the emails always come as if sent from my Gmail email address. Is this a security restriction they've put in place at Gmail to stop spammers using their SMTP? Note: I've tried both of the following methods within my ActionMailer (just in case): @from = me@mydomain.com from 'me@mydomain.com' I believe it's just something Gmail does when mail is sent through its SMTP, as it was mentioned that they do this on a tutorial about using their SMTP to

Sending email from Gmail Rails 3

那年仲夏 提交于 2019-11-29 07:27:17
I'm trying to send an email through my gmail account. I copied the code directly from the rails guide, and in my terminal it's saying that it is sending the message however, the address I'm sending it to is not getting it. Here is the code I have in my env.rb file config.action_mailer.deconfig.action_mailer.delivery_method = :smtp config.action_mailer.smtp_settings = { :address => "smtp.gmail.com", :port => 587, :domain => 'derp' :user_name => 'derp.bot', :password => 'derp42069', :authentication => 'plain', :enable_starttls_auto => true } In the terminal, I'm getting the following message:

Ruby on Rails 3.2 Mailer, localize mail subject field

让人想犯罪 __ 提交于 2019-11-29 06:57:38
I'm currently writing a mailer in RoR 3.2 that would send out mails that should be localized based on a users' language. I managed to render the correct localized views but I'm having some difficulties with some fields that require changing the locale (like the subject). I've already read some posts that are against changing the locale before sending the email. The users have many different languages and that would mean changing my locale every time a user is sent an email. I know that it would be possible to change the locale, send the email, change back the locale. This doesn't feel like the