Rails 보전 의 제6 1 식:Sending Email
1,config/environments/development.rb 수정,smtp 설정
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 = {
:address => 'smtp.example.com',
:port => 25,
:domain => 'www.example.com',
:authentication => :login,
:user_name => 'www',
:password => 'secret'
}
production 환경 에서 위 설정 을 environment.rb 로 옮 깁 니 다.
2,mailer 생 성
ruby script/generate mailer user_mailer
3,UserMailer 수정
class UserMailer < ActionMailer::Base
def registration_confirmation(user)
recipients user.email
from "[email protected]"
subject "Thank you for Registering"
body :user => user
end
end
4,수정 이메일 템 플 릿 views/usermailer/registration_confirmation.rhtml
Hi <%= @user.name %>,
...
5,Users Controller 에서 UserMailer 사용
class UsersController < ApplicationController
def create
@user = User.new(params[:user])
if @user.save
UserMailer.deliver_registration_confirmation(@user)
flash[:notice] = "Successfully registered"
redirect_to user_path(@user)
else
render :action => 'new'
end
end
# ...
end
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
writeFlashHTML, 주로 Flash 출력에 사용되는 JS 방법입니다.텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.