classUserNotifierMailer<ApplicationMailer::Basedefault:from=>'any_from_address@example.com'# send a signup email to the user, pass in the user object that contains the user's email addressdefsend_signup_email(user)@user=usermail(:to=>@user.email,:subject=>'Thanks for signing up for our amazing app')endend
<!DOCTYPE html><html><head><metacontent='text/html; charset=UTF-8'http-equiv='Content-Type'/></head><body><h1>Thanks for signing up, <%= @user.name %>!</h1><p>Thanks for joining and have a great day! Now sign in and do
awesome things!</p></body></html>
userモデルがまだ無い場合、以下のように生成することができます:
12
$ rails generate scaffold user name email login
$ rake db:migrate
classUsersController<ApplicationControllerdefcreate# Create the user from params@user=User.new(user_params[:user])if@user.save# Deliver the signup emailUserNotifierMailer.send_signup_email(@user).deliverredirect_to(@user,:notice=>'User created')elserender:action=>'new'endendprivatedefuser_paramsparams.require(:user).permit(:name,:email,:login)endend
ActionMailer::Base.smtp_settings={:user_name=>'apikey',# This is the string literal 'apikey', NOT the ID of your API key:password=>'<SENDGRID_API_KEY>',# This is the secret sendgrid API key which was issued during API key creation:domain=>'yourdomain.com',:address=>'smtp.sendgrid.net',:port=>587,:authentication=>:plain,:enable_starttls_auto=>true}