Last active
August 29, 2015 14:26
-
-
Save Yama-to/602f5ab3165cb326921b to your computer and use it in GitHub Desktop.
Railsでメール自動配信機能をつくるまでの道程 ref: http://qiita.com/Yama-to/items/823baf26bba3193712ea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ApplicationMailer < ActionMailer::Base | |
default from: "メールテスト運営局", | |
bcc: "[email protected]", | |
reply_to: "[email protected]" | |
layout 'mailer' | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ rails g mailer SampleMailer send_when_update | |
# rails g mailer <メーラー名> <メソッド名> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
attachments.inline[@avatar_file] = | |
File.read(Rails.root.join("public#{avatar_url(@user)}")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<p> | |
ユーザー名: <%= @user.name %><br /> | |
アバター画像:<br /> | |
<%= image_tag attachments[@avatar_file].url %> | |
</p> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
=============================== | |
<%= @user.name %>様 | |
=============================== | |
この度は「メールテスト運営局」を利用頂きましてありがとうございます。 | |
ユーザー名: <%= @user.name %> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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