module JamRuby # UserMailer must be configured to work # Some common configs occur in jam_ruby/init.rb # Environment specific configs occur in spec_helper.rb in jam-ruby and jam-web (to put it into test mode), # and in config/initializers/email.rb in rails to configure sendmail account settings # If UserMailer were to be used in another project, it would need to be configured there, as well. # Templates for UserMailer can be found in jam_ruby/app/views/jam_ruby/user_mailer class UserMailer < ActionMailer::Base include SendGrid layout "user_mailer" DEFAULT_SENDER = "JamKazam " default :from => DEFAULT_SENDER sendgrid_category :use_subject_lines #sendgrid_enable :opentrack, :clicktrack # this makes our emails creepy, imo (seth) sendgrid_unique_args :env => Environment.mode def confirm_email(user, signup_confirm_url) @user = user @signup_confirm_url = signup_confirm_url sendgrid_category "Confirm Email" sendgrid_unique_args :type => "confirm_email" sendgrid_recipients([user.email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => user.email, :subject => "Please confirm your JamKazam email") do |format| format.text format.html end end def welcome_message(user) @user = user sendgrid_category "Welcome" sendgrid_unique_args :type => "welcome_message" sendgrid_recipients([user.email]) sendgrid_substitute('@USERID', [user.id]) sendgrid_substitute(EmailBatchProgression::VAR_FIRST_NAME, [user.first_name]) mail(:to => user.email, :subject => "Welcome to JamKazam") do |format| format.text format.html end end def student_welcome_message(user) @user = user @subject = "Welcome to JamKazam and JamClass online lessons!" sendgrid_category "Welcome" sendgrid_unique_args :type => "welcome_message" sendgrid_recipients([user.email]) sendgrid_substitute('@USERID', [user.id]) sendgrid_substitute(EmailBatchProgression::VAR_FIRST_NAME, [user.first_name]) mail(:to => user.email, :subject => @subject) do |format| format.text format.html end end def teacher_welcome_message(user) @user = user @subject= "Welcome to JamKazam and JamClass online lessons!" sendgrid_category "Welcome" sendgrid_unique_args :type => "welcome_message" sendgrid_recipients([user.email]) sendgrid_substitute('@USERID', [user.id]) sendgrid_substitute(EmailBatchProgression::VAR_FIRST_NAME, [user.first_name]) mail(:to => user.email, :subject => @subject) do |format| format.text format.html end end def school_owner_welcome_message(user) @user = user @subject= "Welcome to JamKazam and JamClass online lessons!" sendgrid_category "Welcome" sendgrid_unique_args :type => "welcome_message" sendgrid_recipients([user.email]) sendgrid_substitute('@USERID', [user.id]) sendgrid_substitute(EmailBatchProgression::VAR_FIRST_NAME, [user.first_name]) mail(:to => user.email, :subject => @subject) do |format| format.text format.html end end def password_changed(user) @user = user sendgrid_recipients([user.email]) sendgrid_substitute('@USERID', [user.id]) sendgrid_unique_args :type => "password_changed" mail(:to => user.email, :subject => "JamKazam Password Changed") do |format| format.text format.html end end def password_reset(user, password_reset_url) @user = user sendgrid_recipients([user.email]) sendgrid_substitute('@USERID', [user.id]) @password_reset_url = password_reset_url sendgrid_unique_args :type => "password_reset" mail(:to => user.email, :subject => "JamKazam Password Reset") do |format| format.text format.html end end def updating_email(user) @user = user sendgrid_recipients([user.email]) sendgrid_substitute('@USERID', [user.id]) sendgrid_unique_args :type => "updating_email" mail(:to => user.update_email, :subject => "JamKazam Email Change Confirmation") do |format| format.text format.html end end def updated_email(user) @user = user sendgrid_recipients([user.email]) sendgrid_substitute('@USERID', [user.id]) sendgrid_unique_args :type => "updated_email" mail(:to => user.email, :subject => "JamKazam Email Changed") do |format| format.text format.html end end def new_musicians(user, new_musicians, host='www.jamkazam.com') @user, @new_musicians, @host = user, new_musicians, host sendgrid_recipients([user.email]) sendgrid_substitute('@USERID', [user.id]) sendgrid_unique_args :type => "new_musicians" mail(:to => user.email, :subject => EmailBatchNewMusician.subject) do |format| format.text format.html end end #################################### NOTIFICATION EMAILS #################################### def friend_request(user, msg, friend_request_id) return if !user.subscribe_email email = user.email subject = "You have a new friend request on JamKazam" unique_args = {:type => "friend_request"} @url = Nav.accept_friend_request_dialog(friend_request_id) @body = msg sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def friend_request_accepted(user, msg) return if !user.subscribe_email email = user.email subject = "You have a new friend on JamKazam" unique_args = {:type => "friend_request_accepted"} @body = msg sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def new_user_follower(user, msg) return if !user.subscribe_email email = user.email subject = "You have a new follower on JamKazam" unique_args = {:type => "new_user_follower"} @body = msg sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def new_band_follower(user, msg) return if !user.subscribe_email email = user.email subject = "Your band has a new follower on JamKazam" unique_args = {:type => "new_band_follower"} @body = msg sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def session_invitation(user, msg) return if !user.subscribe_email email = user.email subject = "You have been invited to a session on JamKazam" unique_args = {:type => "session_invitation"} @body = msg sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def musician_session_join(user, msg, session_id) return if !user.subscribe_email email = user.email subject = "Someone you know is in a session on JamKazam" unique_args = {:type => "musician_session_join"} @body = msg @session_url = "#{APP_CONFIG.external_root_url}/sessions/#{session_id}" sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def scheduled_session_invitation(user, msg, session) return if !user.subscribe_email email = user.email subject = "Session Invitation" unique_args = {:type => "scheduled_session_invitation"} @body = msg @session_name = session.name @session_date = session.pretty_scheduled_start(true) @session_url = "#{APP_CONFIG.external_root_url}/sessions/#{session.id}/details" sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def scheduled_session_rsvp(user, msg, session) return if !user.subscribe_email email = user.email subject = "Session RSVP" unique_args = {:type => "scheduled_session_rsvp"} @body = msg @session_name = session.name @session_date = session.pretty_scheduled_start(true) @session_url = "#{APP_CONFIG.external_root_url}/sessions/#{session.id}/details" sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def scheduled_session_rsvp_approved(user, msg, session) return if !user.subscribe_email email = user.email subject = "Session RSVP Approved" unique_args = {:type => "scheduled_session_rsvp_approved"} @body = msg @session_name = session.name @session_date = session.pretty_scheduled_start(true) @session_url = "#{APP_CONFIG.external_root_url}/sessions/#{session.id}/details" sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def scheduled_session_rsvp_cancelled(user, msg, session) return if !user.subscribe_email email = user.email subject = "Session RSVP Cancelled" unique_args = {:type => "scheduled_session_rsvp_cancelled"} @body = msg @session_name = session.name @session_date = session.pretty_scheduled_start(true) @session_url = "#{APP_CONFIG.external_root_url}/sessions/#{session.id}/details" sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def scheduled_session_rsvp_cancelled_org(user, msg, session) return if !user.subscribe_email email = user.email subject = "Your Session RSVP Cancelled" unique_args = {:type => "scheduled_session_rsvp_cancelled_org"} @body = msg @session_name = session.name @session_date = session.pretty_scheduled_start(true) @session_url = "#{APP_CONFIG.external_root_url}/sessions/#{session.id}/details" sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def scheduled_session_cancelled(user, msg, session) return if !user.subscribe_email email = user.email subject = "Session Cancelled" unique_args = {:type => "scheduled_session_cancelled"} @body = msg @session_name = session.name @session_date = session.pretty_scheduled_start(true) @session_url = "#{APP_CONFIG.external_root_url}/sessions/#{session.id}/details" sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def scheduled_session_rescheduled(user, msg, session) return if !user.subscribe_email email = user.email subject = "Session Rescheduled" unique_args = {:type => "scheduled_session_rescheduled"} @body = msg @session_name = session.name @session_date = session.pretty_scheduled_start(true) @session_url = "#{APP_CONFIG.external_root_url}/sessions/#{session.id}/details" sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def scheduled_session_reminder_upcoming(user, session) subject = "Your JamKazam session starts in 1 hour!" unique_args = {:type => "scheduled_session_reminder_upcoming"} send_scheduled_session_reminder(user, session, subject, unique_args) end def scheduled_session_reminder_day(user, session) subject = "JamKazam Session Reminder" unique_args = {:type => "scheduled_session_reminder_day"} send_scheduled_session_reminder(user, session, subject, unique_args) end def send_scheduled_session_reminder(user, session, subject, unique_args) return if !user.subscribe_email email = user.email @user = user @session_name = session.name @session_date = session.pretty_scheduled_start(true) @session_url = "#{APP_CONFIG.external_root_url}/sessions/#{session.id}/details" sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def scheduled_session_comment(target_user, sender, msg, comment, session) return if !target_user.subscribe_email email = target_user.email subject = "New Session Comment" unique_args = {:type => "scheduled_session_comment"} @body = msg @session_name = session.name @session_date = session.pretty_scheduled_start(true) @comment = comment @sender = sender @suppress_user_has_account_footer = true @session_url = "#{APP_CONFIG.external_root_url}/sessions/#{session.id}/details" sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [target_user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def scheduled_session_daily(receiver, sessions_and_latency) sendgrid_category "Notification" sendgrid_unique_args :type => "scheduled_session_daily" sendgrid_recipients([receiver.email]) sendgrid_substitute('@USERID', [receiver.id]) @user = receiver @sessions_and_latency = sessions_and_latency @title = 'New Scheduled Sessions Matched to You' mail(:to => receiver.email, :subject => EmailBatchScheduledSessions.subject) do |format| format.text format.html end end def band_session_join(user, msg, session_id) return if !user.subscribe_email email = user.email subject = "A band that you follow has joined a session" unique_args = {:type => "band_session_join"} @body = msg @session_url = "#{APP_CONFIG.external_root_url}/sessions/#{session_id}" sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def musician_recording_saved(user, msg) return if !user.subscribe_email email = user.email subject = "A musician has saved a new recording on JamKazam" unique_args = {:type => "musician_recording_saved"} @body = msg sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def band_recording_saved(user, msg) return if !user.subscribe_email email = user.email subject = "A band has saved a new recording on JamKazam" unique_args = {:type => "band_recording_saved"} @body = msg sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def band_invitation(user, msg) return if !user.subscribe_email email = user.email subject = "You have been invited to join a band on JamKazam" unique_args = {:type => "band_invitation"} @body = msg sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def band_invitation_accepted(user, msg) return if !user.subscribe_email email = user.email subject = "Your band invitation was accepted" unique_args = {:type => "band_invitation_accepted"} @body = msg sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html end end def text_message(user, sender_id, sender_name, sender_photo_url, message) return if !user.subscribe_email email = user.email subject = "Message from #{sender_name}" unique_args = {:type => "text_message"} @note = message @url = Nav.home(dialog: 'text-message', dialog_opts: {d1: sender_id}) @sender_id = sender_id @sender_name = sender_name @sender_photo_url = sender_photo_url sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def student_lesson_request(lesson_booking) email = lesson_booking.user.email subject = "You have sent a lesson request to #{lesson_booking.teacher.name}!" unique_args = {:type => "student_lesson_request"} @sender = lesson_booking.teacher @lesson_booking = lesson_booking sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [lesson_booking.user.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def teacher_lesson_request(lesson_booking) email = lesson_booking.teacher.email subject = "You have received a lesson request through JamKazam!" unique_args = {:type => "teacher_lesson_request"} @sender = lesson_booking.user @lesson_booking = lesson_booking sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [lesson_booking.teacher.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def student_lesson_accepted(lesson_session, message, slot) @slot = slot if slot.is_teacher_approved? @target = lesson_session.student @sender = lesson_session.teacher @subject = "Your lesson request is confirmed!" else @target = lesson_session.teacher @sender = lesson_session.student @subject = "Your have confirmed a lesson!" end @lesson_session = lesson_session @message = message email = lesson_session.student.email unique_args = {:type => "student_lesson_accepted"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [lesson_session.student.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def teacher_lesson_accepted(lesson_session, message, slot) @slot = slot if slot.is_teacher_approved? @target = lesson_session.student @sender = lesson_session.teacher @subject = "You have confirmed a lesson!" else @target = lesson_session.teacher @sender = lesson_session.student @subject = "Your lesson time change is confirmed by #{lesson_session.student.name}!" end @lesson_session = lesson_session @message = message email = lesson_session.teacher.email unique_args = {:type => "teacher_lesson_accepted"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [lesson_session.teacher.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def student_lesson_update_all(lesson_session, message, slot) @slot = slot if slot.is_teacher_created? @target = lesson_session.teacher @sender = lesson_session.student subject = "All lesson times changed with #{lesson_session.teacher.name}!" else @target = lesson_session.student @sender = lesson_session.teacher subject = "All lesson times changed with #{lesson_session.teacher.name}!" end @lesson_session = lesson_session @message = message email = lesson_session.student.email unique_args = {:type => "student_lesson_accepted"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [lesson_session.student.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def teacher_lesson_update_all(lesson_session, message, slot) @slot = slot if slot.is_teacher_created? @target = lesson_session.teacher @sender = lesson_session.student subject = "All lesson times changed with #{lesson_session.student.name}!" else @target = lesson_session.student @sender = lesson_session.teacher subject = "All lesson times changed with #{lesson_session.student.name}!" end @lesson_session = lesson_session @message = message email = lesson_session.teacher.email unique_args = {:type => "teacher_lesson_update_all"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [lesson_session.teacher.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def teacher_scheduled_jamclass_invitation(user, msg, session) email = user.email @subject = "#{session.lesson_session.lesson_booking.display_type2.capitalize} JamClass Scheduled with #{session.lesson_session.student.name}" unique_args = {:type => "scheduled_jamclass_invitation"} @student = session.lesson_session.student @teacher = session.lesson_session.teacher @body = msg @session_name = session.name @session_description = session.description @session_date = session.pretty_scheduled_start(true) @session_url = session.lesson_session.web_url sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html end end def student_scheduled_jamclass_invitation(user, msg, session) return if !user.subscribe_email email = user.email @subject = "#{session.lesson_session.lesson_booking.display_type2.capitalize} JamClass Scheduled with #{session.lesson_session.teacher.name}" unique_args = {:type => "scheduled_jamclass_invitation"} @student = session.lesson_session.student @teacher = session.lesson_session.teacher @body = msg @session_name = session.name @session_description = session.description @session_date = session.pretty_scheduled_start(true) @session_url = session.lesson_session.web_url sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [user.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html end end # teacher proposed counter time; so send msg to the student def student_lesson_counter(lesson_session, slot) email = lesson_session.student.email subject = "Instructor has proposed a different time for your lesson" unique_args = {:type => "student_lesson_counter"} @student = lesson_session.student @teacher = lesson_session.teacher @session_name = lesson_session.music_session.name @session_description = lesson_session.music_session.description @session_date = slot.pretty_scheduled_start(true) @session_url = lesson_session.web_url @lesson_session = lesson_session sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@student.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end # student proposed counter time; so send msg to the teacher def teacher_lesson_counter(lesson_session, slot) email = lesson_session.teacher.email subject = "Student has proposed a different time for their lesson" unique_args = {:type => "teacher_lesson_counter"} @student = lesson_session.student @teacher = lesson_session.teacher @session_name = lesson_session.music_session.name @session_description = lesson_session.music_session.description @session_date = slot.pretty_scheduled_start(true) @session_url = lesson_session.web_url @lesson_session = lesson_session sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@teacher.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def teacher_lesson_completed(lesson_session) @student = lesson_session.student @teacher = lesson_session.teacher @session_name = lesson_session.music_session.name @session_description = lesson_session.music_session.description @session_date = lesson_session.slot.pretty_scheduled_start(true) @session_url = lesson_session.web_url @lesson_session = lesson_session email = lesson_session.teacher.email if @lesson_session.student_missed subject = "You will be paid for your lesson with #{@student.name}" else subject = "You successfully completed a lesson with #{@student.name}" end unique_args = {:type => "teacher_lesson_completed"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@teacher.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end # successfully completed, and has some remaining test drives def student_test_drive_lesson_completed(lesson_session) @student = lesson_session.student @teacher = lesson_session.teacher @session_name = lesson_session.music_session.name @session_description = lesson_session.music_session.description @session_date = lesson_session.slot.pretty_scheduled_start(true) @session_url = lesson_session.web_url @lesson_session = lesson_session email = @student.email subject = "You have used #{@student.used_test_drives} of #{@student.total_test_drives} TestDrive lesson credits" unique_args = {:type => "student_test_drive_success"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@student.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def teacher_test_drive_no_bill(lesson_session) @student = lesson_session.student @teacher = lesson_session.teacher @session_name = lesson_session.music_session.name @session_description = lesson_session.music_session.description @session_date = lesson_session.slot.pretty_scheduled_start(true) @session_url = lesson_session.web_url @lesson_session = lesson_session email = @teacher.email subject = "Your TestDrive with #{@student.name} was not successful" unique_args = {:type => "teacher_test_drive_no_bill"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@teacher.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def student_test_drive_no_bill(lesson_session) @student = lesson_session.student @teacher = lesson_session.teacher @session_name = lesson_session.music_session.name @session_description = lesson_session.music_session.description @session_date = lesson_session.slot.pretty_scheduled_start(true) @session_url = lesson_session.web_url @lesson_session = lesson_session email = @student.email subject = "Your TestDrive with #{@teacher.name} will not use a credit" unique_args = {:type => "student_test_drive_no_bill"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@student.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end # successfully completed, but no more test drives left def student_test_drive_lesson_done(lesson_session) @student = lesson_session.student @teacher = lesson_session.teacher @session_name = lesson_session.music_session.name @session_description = lesson_session.music_session.description @session_date = lesson_session.slot.pretty_scheduled_start(true) @session_url = lesson_session.web_url @lesson_session = lesson_session email = @student.email subject = "You have used all TestDrive lesson credits" unique_args = {:type => "student_test_drive_success"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@student.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "raw_mailer" } end end def student_lesson_normal_no_bill(lesson_session) @student = lesson_session.student @teacher = lesson_session.teacher @session_name = lesson_session.music_session.name @session_description = lesson_session.music_session.description @session_date = lesson_session.slot.pretty_scheduled_start(true) @session_url = lesson_session.web_url @lesson_session = lesson_session email = @student.email subject = "Your lesson with #{@teacher.name} will not be billed" unique_args = {:type => "student_lesson_normal_no_bill"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@student.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def teacher_lesson_normal_no_bill(lesson_session) @student = lesson_session.student @teacher = lesson_session.teacher @session_name = lesson_session.music_session.name @session_description = lesson_session.music_session.description @session_date = lesson_session.slot.pretty_scheduled_start(true) @session_url = lesson_session.web_url @lesson_session = lesson_session email = lesson_session.teacher.email subject = "Your student #{@student.name} will not be charged for their lesson" unique_args = {:type => "teacher_lesson_normal_no_bill"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@teacher.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def student_lesson_normal_done(lesson_session) @student = lesson_session.student @teacher = lesson_session.teacher @session_name = lesson_session.music_session.name @session_description = lesson_session.music_session.description @session_date = lesson_session.slot.pretty_scheduled_start(true) @session_url = lesson_session.web_url @lesson_session = lesson_session email = @student.email subject = "Your JamClass lesson today with #{@teacher.first_name}" unique_args = {:type => "student_lesson_normal_done"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@student.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def teacher_lesson_normal_done(lesson_session) @student = lesson_session.student @teacher = lesson_session.teacher @session_name = lesson_session.music_session.name @session_description = lesson_session.music_session.description @session_date = lesson_session.slot.pretty_scheduled_start(true) @session_url = lesson_session.web_url @lesson_session = lesson_session email = lesson_session.teacher.email subject = "Your JamClass lesson today with #{@student.first_name}" unique_args = {:type => "teacher_lesson_normal_done"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@teacher.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def student_unable_charge(lesson_session) @student = lesson_session.student @teacher = lesson_session.teacher @session_name = lesson_session.music_session.name @session_description = lesson_session.music_session.description @session_date = lesson_session.slot.pretty_scheduled_start(true) @session_url = lesson_session.web_url @lesson_session = lesson_session @card_declined = lesson_session.is_card_declined? @card_expired = lesson_session.is_card_expired? @bill_date = lesson_session.last_billed_at_date email = @student.email subject = "The credit card charge for your lesson today with #{@teacher.name} failed" unique_args = {:type => "student_unable_charge"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@student.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def teacher_unable_charge(lesson_session) @student = lesson_session.student @teacher = lesson_session.teacher @session_name = lesson_session.music_session.name @session_description = lesson_session.music_session.description @session_date = lesson_session.slot.pretty_scheduled_start(true) @session_url = lesson_session.web_url @lesson_session = lesson_session email = lesson_session.teacher.email subject = "The credit card charge for your lesson today with #{@teacher.name} failed" unique_args = {:type => "teacher_lesson_normal_done"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@teacher.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def student_unable_charge_monthly(lesson_package_purchase) lesson_booking = lesson_package_purchase.lesson_booking @student = lesson_booking.student @teacher = lesson_booking.teacher @lesson_package_purchase = lesson_package_purchase @card_declined = lesson_package_purchase.is_card_declined? @card_expired = lesson_package_purchase.is_card_expired? @bill_date = lesson_package_purchase.last_billed_at_date @lesson_booking = lesson_booking @month_name = lesson_package_purchase.month_name email = @student.email if lesson_booking.is_suspended? @subject = "Your weekly lessons with #{@teacher.name} have been suspended." else @subject = "The credit card charge for your #{@month_name} lessons with #{@teacher.name} failed." end unique_args = {:type => "student_unable_charge_monthly"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@student.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def teacher_unable_charge_monthly(lesson_package_purchase) lesson_booking = lesson_package_purchase.lesson_booking @student = lesson_booking.student @teacher = lesson_booking.teacher @lesson_package_purchase = lesson_package_purchase @card_declined = lesson_package_purchase.is_card_declined? @card_expired = lesson_package_purchase.is_card_expired? @bill_date = lesson_package_purchase.last_billed_at_date @lesson_booking = lesson_booking @month_name = lesson_package_purchase.month_name email = @teacher.email if lesson_booking.is_suspended? @subject = "Your weekly lessons with #{@student.name} has been suspended." else @subject = "The student #{@student.name} had a failed credit card charge for #{@month_name}." end unique_args = {:type => "teacher_unable_charge_monthly"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@teacher.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def student_lesson_monthly_charged(lesson_package_purchase) lesson_booking = lesson_package_purchase.lesson_booking @student = lesson_booking.student @teacher = lesson_booking.teacher @lesson_package_purchase = lesson_package_purchase @card_declined = lesson_package_purchase.is_card_declined? @card_expired = lesson_package_purchase.is_card_expired? @bill_date = lesson_package_purchase.last_billed_at_date @lesson_booking = lesson_booking @month_name = lesson_package_purchase.month_name email = @student.email @subject = "Your JamClass lessons with #{@teacher.first_name} for #{@month_name}" unique_args = {:type => "student_lesson_monthly_charged"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@student.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def teacher_lesson_monthly_charged(lesson_package_purchase) lesson_booking = lesson_package_purchase.lesson_booking @student = lesson_booking.student @teacher = lesson_booking.teacher @lesson_package_purchase = lesson_package_purchase @card_declined = lesson_package_purchase.is_card_declined? @card_expired = lesson_package_purchase.is_card_expired? @bill_date = lesson_package_purchase.last_billed_at_date @lesson_booking = lesson_booking @month_name = lesson_package_purchase.month_name email = @teacher.email if lesson_booking.is_suspended? @subject = "Your weekly lessons with #{@student.name} has been suspended." else @subject = "The student #{@student.name} had a failed credit card charge for #{@month_name}." end unique_args = {:type => "student_lesson_monthly_charged"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@teacher.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end # always goes to the teacher def teacher_distribution_done(teacher_payment) @school = teacher_payment.school @teacher_payment = teacher_payment @distribution = teacher_payment.teacher_distribution @teacher = teacher_payment.teacher @payable_teacher = teacher_payment.payable_teacher @name = @teacher.first_name || 'Anonymous' @student = @distribution.student email = @teacher.email if @school if @distribution.is_test_drive? @subject = "Your TestDrive lesson with #{@student.name}" elsif @distribution.is_normal? @subject = "Your lesson with #{@student.name}" elsif @distribution.is_monthly? @subject = "Your #{@distribution.month_name} lessons with #{@student.name}" else @subject = "Your lesson with #{@student.name}" end else if @distribution.is_test_drive? @subject = "You have earned #{@distribution.real_distribution_display} for your TestDrive lesson with #{@student.first_name}" elsif @distribution.is_normal? @subject = "You have earned #{@distribution.real_distribution_display} for your lesson with #{@student.first_name}" elsif @distribution.is_monthly? @subject = "You have earned #{@distribution.real_distribution_display} for your #{@distribution.month_name} lessons with #{@student.first_name}" else @subject = "You have earned #{@distribution.real_distribution_display} for your lesson with #{@student.first_name}" end end unique_args = {:type => "teacher_distribution_done"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@teacher.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html end end # if school, goes to school owner; otherwise goes to teacher def teacher_distribution_fail(teacher_payment) @school = teacher_payment.school @teacher_payment = teacher_payment @distribution = teacher_payment.teacher_distribution @teacher = teacher_payment.teacher @payable_teacher = teacher_payment.payable_teacher @student = @distribution.student @name = @payable_teacher.first_name || 'Anonymous' email = @payable_teacher.email @card_declined = teacher_payment.is_card_declined? @card_expired = teacher_payment.is_card_expired? @bill_date = teacher_payment.last_billed_at_date if @school if @distribution.is_test_drive? @subject = "We had a problem paying #{@distribution.real_distribution_display} for #{@teacher.name}'s TestDrive lesson with #{@student.name}" elsif @distribution.is_normal? @subject = "We had a problem paying #{@distribution.real_distribution_display} for #{@teacher.name}'s lesson with #{@student.name}" elsif @distribution.is_monthly? @subject = "We had a problem paying #{@distribution.real_distribution_display} for #{@teacher.name}'s #{@distribution.month_name} lessons with #{@student.name}" else @subject = "We had a problem paying #{@distribution.real_distribution_display} for #{@teacher.name}'s lesson with #{@student.name}" end else if @distribution.is_test_drive? @subject = "We had a problem paying you #{@distribution.real_distribution_display} for your TestDrive lesson with #{@student.first_name}" elsif @distribution.is_normal? @subject = "We had a problem paying you #{@distribution.real_distribution_display} for your lesson with #{@student.first_name}" elsif @distribution.is_monthly? @subject = "We had a problem paying you #{@distribution.real_distribution_display} for your #{@distribution.month_name} lessons with #{@student.first_name}" else @subject = "We had a problem paying you #{@distribution.real_distribution_display} for your lesson with #{@student.first_name}" end end unique_args = {:type => "teacher_distribution_fail"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@payable_teacher.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html end end # always goes to the school owner def school_distribution_done(teacher_payment) @school = teacher_payment.school @teacher_payment = teacher_payment @distribution = teacher_payment.teacher_distribution @teacher = teacher_payment.teacher @payable_teacher = @school.owner @name = @payable_teacher.first_name || 'Anonymous' @student = @distribution.student email = @payable_teacher.email if @distribution.is_test_drive? @subject = "#{@teacher.name} has earned #{@distribution.real_distribution_display} for TestDrive lesson with #{@student.name}" elsif @distribution.is_normal? @subject = "#{@teacher.name} has earned #{@distribution.real_distribution_display} for a lesson with #{@student.name}" elsif @distribution.is_monthly? @subject = "#{@teacher.name} has earned #{@distribution.real_distribution_display} for #{@distribution.month_name} lessons with #{@student.name}" else @subject = "#{@teacher.name} has earned #{@distribution.real_distribution_display} for a lesson with #{@student.name}" end unique_args = {:type => "school_distribution_done"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@payable_teacher.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html end end def monthly_recurring_done(lesson_session) @student = lesson_session.student @teacher = lesson_session.teacher @session_name = lesson_session.music_session.name @session_description = lesson_session.music_session.description @session_date = lesson_session.slot.pretty_scheduled_start(true) @session_url = lesson_session.web_url @lesson_session = lesson_session email = @student.email subject = "Your JamClass lesson today with #{@teacher.first_name}" unique_args = {:type => "student_lesson_normal_no_bill"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@student.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def monthly_recurring_no_bill(lesson_session) @student = lesson_session.student @teacher = lesson_session.teacher @session_name = lesson_session.music_session.name @session_description = lesson_session.music_session.description @session_date = lesson_session.slot.pretty_scheduled_start(true) @session_url = lesson_session.web_url @lesson_session = lesson_session email = @student.email subject = "Your lesson with #{@teacher.name} will not be billed" unique_args = {:type => "student_lesson_normal_done"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@student.id]) mail(:to => email, :subject => subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def student_lesson_booking_declined(lesson_booking, message) @lesson_booking = lesson_booking @student = lesson_booking.student @teacher = lesson_booking.teacher @message = message @lesson_session = lesson_booking.next_lesson @session_name = @lesson_session.music_session.name @session_description = @lesson_session.music_session.description @session_date = @lesson_session.slot.pretty_scheduled_start(true) email = @student.email @subject = "We're sorry your lesson request has been declined" unique_args = {:type => "student_lesson_booking_declined"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@student.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def student_lesson_booking_canceled(lesson_booking, message) @lesson_booking = lesson_booking @student = lesson_booking.student @teacher = lesson_booking.teacher @message = message @lesson_session = lesson_booking.next_lesson @session_name = @lesson_session.music_session.name @session_description = @lesson_session.music_session.description @session_date = @lesson_session.slot.pretty_scheduled_start(true) email = @student.email @subject = "Your lesson has been canceled" unique_args = {:type => "student_lesson_booking_canceled"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@student.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def teacher_lesson_booking_canceled(lesson_booking, message) @lesson_booking = lesson_booking @student = lesson_booking.student @teacher = lesson_booking.teacher @message = message @lesson_session = lesson_booking.next_lesson @session_name = @lesson_session.music_session.name @session_description = @lesson_session.music_session.description @session_date = @lesson_session.slot.pretty_scheduled_start(true) email = @teacher.email @subject = "Your lesson has been canceled" unique_args = {:type => "teacher_lesson_booking_canceled"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@teacher.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def student_lesson_canceled(lesson_session, message) @lesson_booking = lesson_booking = lesson_session.lesson_booking @student = lesson_booking.student @teacher = lesson_booking.teacher @message = message @lesson_session = lesson_booking.next_lesson @session_name = @lesson_session.music_session.name @session_description = @lesson_session.music_session.description @session_date = @lesson_session.slot.pretty_scheduled_start(true) email = @student.email @subject = "Your lesson has been canceled" unique_args = {:type => "student_lesson_canceled"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@student.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def teacher_lesson_canceled(lesson_session, message) @lesson_booking = lesson_booking = lesson_session.lesson_booking @student = lesson_booking.student @teacher = lesson_booking.teacher @message = message @lesson_session = lesson_booking.next_lesson @session_name = @lesson_session.music_session.name @session_description = @lesson_session.music_session.description @session_date = @lesson_session.slot.pretty_scheduled_start(true) email = @teacher.email @subject = "Your lesson has been canceled" unique_args = {:type => "teacher_lesson_canceled"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@teacher.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def invite_school_teacher(school_invitation) @school_invitation = school_invitation @school = school_invitation.school email = school_invitation.email @subject = "#{@school.owner.name} has sent you an invitation to join #{@school.name} on JamKazam" unique_args = {:type => "invite_school_teacher"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) @suppress_user_has_account_footer = true mail(:to => email, :subject => @subject) do |format| format.text format.html end end def invite_school_student(school_invitation) @school_invitation = school_invitation @school = school_invitation.school email = school_invitation.email @subject = "#{@school.name} has sent you an invitation to join JamKazam for lessons" unique_args = {:type => "invite_school_student"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) @suppress_user_has_account_footer = true mail(:to => email, :subject => @subject) do |format| format.text format.html end end def lesson_chat(chat_msg) @target = chat_msg.target_user @sender = chat_msg.user @message = chat_msg.message @lesson_session = chat_msg.lesson_session @session_name = @lesson_session.music_session.name @session_description = @lesson_session.music_session.description @session_date = @lesson_session.slot.pretty_scheduled_start(true) email = @target.email @subject = "#{@sender.name} has sent you a message about a lesson" unique_args = {:type => "lesson_chat"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@target.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def lesson_starting_soon_teacher(lesson_session) @lesson_booking = lesson_booking = lesson_session.lesson_booking @student = lesson_booking.student @teacher = lesson_booking.teacher @lesson_session = lesson_booking.next_lesson @session_name = @lesson_session.music_session.name @session_description = @lesson_session.music_session.description @session_date = @lesson_session.slot.pretty_scheduled_start(true) email = @teacher.email @subject = "Your lesson with #{@student.first_name} on JamKazam is starting soon" unique_args = {:type => "send_starting_notice_teacher"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@teacher.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end def lesson_starting_soon_student(lesson_session) @lesson_booking = lesson_booking = lesson_session.lesson_booking @student = lesson_booking.student @teacher = lesson_booking.teacher @message = message @lesson_session = lesson_booking.next_lesson @session_name = @lesson_session.music_session.name @session_description = @lesson_session.music_session.description @session_date = @lesson_session.slot.pretty_scheduled_start(true) email = @student.email @subject = "Your lesson with #{@teacher.first_name} on JamKazam is starting soon" unique_args = {:type => "send_starting_notice_student"} sendgrid_category "Notification" sendgrid_unique_args :type => unique_args[:type] sendgrid_recipients([email]) sendgrid_substitute('@USERID', [@student.id]) mail(:to => email, :subject => @subject) do |format| format.text format.html { render :layout => "from_user_mailer" } end end end end