· 8 years ago · Aug 01, 2018, 10:42 AM
1Custom mailer settings, not setting Return-path
2class SupportMailer < ActionMailer::Base
3
4 default :from => "supportaddress@gmail.com"
5
6 SMTP_SETTINGS = {
7 :address => "smtp.gmail.com",
8 :port => 587,
9 :domain => "gmail.com",
10 :user_name => "",
11 :password => "",
12 :authentication => "plain",
13 :enable_starttls_auto => true
14 }
15
16 def welcome_email(ticket)
17 with_custom_smtp_settings do
18 @ticket = ticket
19 from "supportaddress@gmail.com"
20 headers["Reply-to"] = "supportaddress+#{ticket.token}@gmail.com"
21 to ticket.email
22 subject = "Welcome"
23 end
24 end
25
26 # Override the deliver! method so that we can reset our custom smtp server settings
27 def deliver!(mail = @mail)
28 out = super
29 reset_smtp_settings if @_temp_smtp_settings
30 out
31 end
32
33 private
34
35 def with_custom_smtp_settings(&block)
36 @_temp_smtp_settings = @@smtp_settings
37 @@smtp_settings = SMTP_SETTINGS
38 yield
39 end
40end