feat: Implement comprehensive email notifications system
This commit implements a complete email notifications system for purchase confirmations and event reminders as requested in the medium priority backlog tasks. ## Features Added ### Purchase Confirmation Emails - Automatically sent when orders are marked as paid - Supports both single tickets and multi-ticket orders - Includes PDF ticket attachments - Professional HTML and text templates in French ### Event Reminder Emails - Automated reminders sent 7 days, 1 day, and day of events - Only sent to users with active tickets - Smart messaging based on time until event - Venue details and ticket information included ### Background Jobs - EventReminderJob: Sends reminders to all users for a specific event - EventReminderSchedulerJob: Daily scheduler to queue reminder jobs - Proper error handling and logging ### Email Templates - Responsive HTML templates with ApéroNight branding - Text fallbacks for better email client compatibility - Dynamic content based on number of tickets and time until event ### Configuration & Testing - Environment-based SMTP configuration for production - Development setup with MailCatcher support - Comprehensive test suite with mocking for PDF generation - Integration tests for end-to-end functionality - Documentation with usage examples ## Technical Implementation - Enhanced TicketMailer with new notification methods - Background job scheduling via Rails initializer - Order model integration for automatic purchase confirmations - Proper associations handling for user/ticket relationships - Configurable via environment variables ## Files Added/Modified - Enhanced app/mailers/ticket_mailer.rb with order support - Added app/jobs/event_reminder_*.rb for background processing - Updated email templates in app/views/ticket_mailer/ - Added automatic scheduling in config/initializers/ - Comprehensive test coverage in test/ directory - Complete documentation in docs/email-notifications.md 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
class ApplicationMailer < ActionMailer::Base
|
||||
default from: "from@example.com"
|
||||
default from: ENV.fetch("MAILER_FROM_EMAIL", "no-reply@aperonight.fr")
|
||||
layout "mailer"
|
||||
end
|
||||
|
||||
@@ -1,5 +1,25 @@
|
||||
class TicketMailer < ApplicationMailer
|
||||
default from: "notifications@aperonight.com"
|
||||
def purchase_confirmation_order(order)
|
||||
@order = order
|
||||
@user = order.user
|
||||
@event = order.event
|
||||
@tickets = order.tickets
|
||||
|
||||
# Generate PDF attachments for all tickets
|
||||
@tickets.each do |ticket|
|
||||
pdf = ticket.to_pdf
|
||||
attachments["ticket-#{@event.name.parameterize}-#{ticket.qr_code[0..7]}.pdf"] = {
|
||||
mime_type: "application/pdf",
|
||||
content: pdf
|
||||
}
|
||||
end
|
||||
|
||||
mail(
|
||||
to: @user.email,
|
||||
subject: "Confirmation d'achat - #{@event.name}",
|
||||
template_name: "purchase_confirmation"
|
||||
)
|
||||
end
|
||||
|
||||
def purchase_confirmation(ticket)
|
||||
@ticket = ticket
|
||||
@@ -18,4 +38,33 @@ class TicketMailer < ApplicationMailer
|
||||
subject: "Confirmation d'achat - #{@event.name}"
|
||||
)
|
||||
end
|
||||
|
||||
def event_reminder(user, event, days_before)
|
||||
@user = user
|
||||
@event = event
|
||||
@days_before = days_before
|
||||
|
||||
# Get user's tickets for this event
|
||||
@tickets = Ticket.joins(:order, :ticket_type)
|
||||
.where(orders: { user: @user }, ticket_types: { event: @event }, status: "active")
|
||||
|
||||
return if @tickets.empty?
|
||||
|
||||
subject = case days_before
|
||||
when 7
|
||||
"Rappel : #{@event.name} dans une semaine"
|
||||
when 1
|
||||
"Rappel : #{@event.name} demain"
|
||||
when 0
|
||||
"C'est aujourd'hui : #{@event.name}"
|
||||
else
|
||||
"Rappel : #{@event.name} dans #{days_before} jours"
|
||||
end
|
||||
|
||||
mail(
|
||||
to: @user.email,
|
||||
subject: subject,
|
||||
template_name: "event_reminder"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user