Skip to content

Instantly share code, notes, and snippets.

@Yama-to
Last active August 29, 2015 14:26
Show Gist options
  • Save Yama-to/602f5ab3165cb326921b to your computer and use it in GitHub Desktop.
Save Yama-to/602f5ab3165cb326921b to your computer and use it in GitHub Desktop.
Railsでメール自動配信機能をつくるまでの道程 ref: http://qiita.com/Yama-to/items/823baf26bba3193712ea
class ApplicationMailer < ActionMailer::Base
default from: "メールテスト運営局",
bcc: "[email protected]",
reply_to: "[email protected]"
layout 'mailer'
end
Rails.application.configure do
#--- 中略 ---#
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
port: 587,
address: 'smtp.gmail.com',
domain: 'smtp.gmail.com',
user_name: '<YOUR EMAIL ADDRESS>',
password: '<YOUR EMAIL PASSWORD>',
authentication: 'login',
enable_starttls_auto: true
}
end
$ rails g mailer SampleMailer send_when_update
# rails g mailer <メーラー名> <メソッド名>
attachments.inline[@avatar_file] =
File.read(Rails.root.join("public#{avatar_url(@user)}"))
<p>
ユーザー名: <%= @user.name %><br />
アバター画像:<br />
<%= image_tag attachments[@avatar_file].url %>
</p>
===============================
<%= @user.name %>様
===============================
この度は「メールテスト運営局」を利用頂きましてありがとうございます。
ユーザー名: <%= @user.name %>
class UsersController < ApplicationController
def update
current_user.update(update_params)
SampleMailer.send_when_update(current_user).deliver
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment