Class: CabooseRets::RetsMailer

Inherits:
ActionMailer::Base
  • Object
show all
Defined in:
app/mailers/caboose_rets/rets_mailer.rb

Instance Method Summary collapse

Instance Method Details

#daily_report(user, new_listings, related_listings) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'app/mailers/caboose_rets/rets_mailer.rb', line 59

def daily_report(user, new_listings, related_listings)
  @user = user
  @new_listings = new_listings
  @related_listings = related_listings
  @site = user.site
  to_address = user.email
  reply_to = @site.contact_email.blank? ? '[email protected]' : @site.contact_email
  @color = @site.theme ? @site.theme.color_main : @site.theme_color
  @domain = "https://#{@site.primary_domain.domain}"
  @domain = "http://dev.pmre.com:3000" if Rails.env.development?
  @url = @domain
  @url += "/real-estate" if @site.id == 541
  @logo_url = @site..url(:large)
  subject = @site.id == 541 ? "New and Suggested Listings from Pritchett-Moore Real Estate" : "New and Suggested Listings from #{@site.description}"
  @logo_url = "https:#{@logo_url}" if !@logo_url.include?('http')
  @unsubscribe_url = "https://#{@site.primary_domain.domain}/rets-unsubscribe?token=7b8v9j#{@user.id}9b6h0c2n"
  mail(
    :to => to_address,
    :from => from_address(@site.id, nil),
    :subject => subject,
    :reply_to => reply_to
  )
end

#from_address(site_id, from_name) ⇒ Object



3
4
5
6
7
8
# File 'app/mailers/caboose_rets/rets_mailer.rb', line 3

def from_address(site_id, from_name)
  settings = Caboose::SmtpConfig.where(:site_id => site_id).first
  fn = from_name.blank? ? (settings ? settings.site.description : "Caboose CMS") : from_name
  fn = fn.gsub(",","").gsub("<","").gsub(">","").gsub("@","").gsub(":","").truncate(30)
  return settings ? "#{fn} <#{settings.from_address}>" : "#{fn} <[email protected]>"
end

#new_user(agent, user) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/mailers/caboose_rets/rets_mailer.rb', line 10

def new_user(agent, user)
  @agent = agent
  @user = user
  @site = user.site
  to_address = Rails.env.development? ? '[email protected]' : agent.email
  bcc_address = Rails.env.development? ? '[email protected]' : @site.contact_email
  mail(
    :to => to_address,
    :bcc => bcc_address,
    :from => from_address(@site.id, nil),
    :subject => "New User Registration",
    :reply_to => bcc_address
  )
end

#property_price_change(user, property, old_price) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'app/mailers/caboose_rets/rets_mailer.rb', line 107

def property_price_change(user, property, old_price)
  @user = user
  @property = property
  @old_price = old_price
  @site = user.site
  to_address = user.email
  reply_to = @site.contact_email.blank? ? '[email protected]' : @site.contact_email
  @color = @site.theme ? @site.theme.color_main : @site.theme_color
  @domain = "https://#{@site.primary_domain.domain}"
  @domain = "http://dev.pmre.com:3000" if Rails.env.development?
  @url = @domain
  @url += "/real-estate" if @site.id == 541
  @logo_url = @site..url(:large)
  subject = "Price Change for Listing MLS ##{@property.mls_number}"
  @logo_url = "https:#{@logo_url}" if !@logo_url.include?('http')
  @unsubscribe_url = "https://#{@site.primary_domain.domain}/rets-unsubscribe?token=7b8v9j#{@user.id}9b6h0c2n"
  mail(
    :to => to_address,
    :from => from_address(@site.id, nil),
    :subject => subject,
    :reply_to => reply_to
  )
end

#property_status_change(user, property, old_status) ⇒ Object



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'app/mailers/caboose_rets/rets_mailer.rb', line 83

def property_status_change(user, property, old_status)
  @user = user
  @property = property
  @old_status = old_status
  @site = user.site
  to_address = user.email
  reply_to = @site.contact_email.blank? ? '[email protected]' : @site.contact_email
  @color = @site.theme ? @site.theme.color_main : @site.theme_color
  @domain = "https://#{@site.primary_domain.domain}"
  @domain = "http://dev.pmre.com:3000" if Rails.env.development?
  @url = @domain
  @url += "/real-estate" if @site.id == 541
  @logo_url = @site..url(:large)
  subject = "Status Change for Listing MLS ##{@property.mls_number}"
  @logo_url = "https:#{@logo_url}" if !@logo_url.include?('http')
  @unsubscribe_url = "https://#{@site.primary_domain.domain}/rets-unsubscribe?token=7b8v9j#{@user.id}9b6h0c2n"
  mail(
    :to => to_address,
    :from => from_address(@site.id, nil),
    :subject => subject,
    :reply_to => reply_to
  )
end

#user_welcome(agent, user) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/mailers/caboose_rets/rets_mailer.rb', line 25

def user_welcome(agent, user)
  @agent = agent
  @user = user
  @site = user.site
  to_address = user.email
  bcc_address = Rails.env.development? ? '[email protected]' : @site.contact_email
  reply_to = @site.contact_email.blank? ? '[email protected]' : @site.contact_email

  setting = Caboose::Setting.where(:site_id => @site.id, :name => "welcome_email_subject").first
  subject = setting && !setting.value.blank? ? setting.value : "Welcome to #{@site.description}"

  setting2 = Caboose::Setting.where(:site_id => @site.id, :name => "welcome_email_body").first
  @body = setting2 && !setting2.value.blank? ? setting2.value : "We're excited to see that you've registered for #{@site.description}. As a registered user, we'll notify you when there's a price drop or pending sale on your favorite properties. We'll also notify you of new listings and similar properties you may be interested in. Your assigned REALTORĀ® is |agent_name| and will be in touch with you shortly. Thank you for choosing #{@site.description}!"
  @body = @body.gsub("|agent_name|", "#{@agent.first_name} #{@agent.last_name}")

  @color = @site.theme ? @site.theme.color_main : @site.theme_color

  @url = "https://#{@site.primary_domain.domain}"
  @url += "/real-estate" if @site.id == 541

  @logo_url = @site..url(:large)
  @logo_url = "https:#{@logo_url}" if !@logo_url.include?('http')

  @unsubscribe_url = "https://#{@site.primary_domain.domain}/rets-unsubscribe?token=7b8v9j#{@user.id}9b6h0c2n"

  mail(
    :to => to_address,
    :bcc => bcc_address,
    :from => from_address(@site.id, nil),
    :subject => subject,
    :reply_to => reply_to
  )
end