Class: WcoEmail::ApplicationMailer
- Inherits:
-
ActionMailer::Base
- Object
- ActionMailer::Base
- WcoEmail::ApplicationMailer
- Defined in:
- app/mailers/wco_email/application_mailer.rb
Overview
test:
WcoEmail::ApplicationMailer.test_email.deliver_now
Class Method Summary collapse
Instance Method Summary collapse
- #forwarder_notify(msg_id) ⇒ Object
- #notify_self(params) ⇒ Object
- #option_alert(option) ⇒ Object
- #send_context_email(ctx_id) ⇒ Object
- #shared_galleries(profiles, gallery) ⇒ Object
- #stock_alert(watch_id) ⇒ Object
- #test_email ⇒ Object
Class Method Details
.renderer(ctx:) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/mailers/wco_email/application_mailer.rb', line 129 def self.renderer ctx: out = self.new out.instance_variable_set( :@ctx, ctx ) out.instance_variable_set( :@lead, ctx.lead ) out.instance_variable_set( :@leadset, ctx.lead.leadset ) out.instance_variable_set( :@utm_tracking_str, ctx.utm_tracking_str ) out.instance_variable_set( :@unsubscribe_url, ctx.unsubscribe_url ) out.instance_variable_set( :@config, ctx.config ) out.instance_variable_set( :@renderer, out ) return out end |
Instance Method Details
#forwarder_notify(msg_id) ⇒ Object
15 16 17 18 19 |
# File 'app/mailers/wco_email/application_mailer.rb', line 15 def forwarder_notify msg_id @msg = WcoEmail::Message.find msg_id mail( to: "poxlovi@gmail.com", subject: "POX::#{@msg.subject}" ) end |
#notify_self(params) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'app/mailers/wco_email/application_mailer.rb', line 21 def notify_self params subject = params[:subject] || 'default subject' body = params[:body] || 'default body' mail( from: DEFAULT_FROM, to: DEFAULT_RECIPIENT, subject: subject, body: body, content_type: "text/text", ); end |
#option_alert(option) ⇒ Object
32 33 34 35 36 37 38 |
# File 'app/mailers/wco_email/application_mailer.rb', line 32 def option_alert option @option = option mail({ :to => option.profile.email, :subject => "IshManager Option Alert :: #{option.ticker}", }) end |
#send_context_email(ctx_id) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/mailers/wco_email/application_mailer.rb', line 40 def send_context_email ctx_id @ctx = Ctx.find ctx_id @renderer = self.class.renderer ctx: @ctx rendered_str = @renderer.render_to_string("/wco_email/email_layouts/_#{@ctx.tmpl.layout}") = Wco::Tag.donotsend.sons + [ Wco::Tag.donotsend ] if ( @ctx.lead. & ).any? @ctx.update({ unsubscribed_at: Time.now }) return end if @ctx.lead.unsubscribed_at.present? @ctx.update({ unsubscribed_at: Time.now }) return end ## for binding only @lead = @ctx.lead lead = @lead @leadset = @ctx.lead.leadset leadset = @leadset rendered_subject = ERB.new( @ctx.subject ).result( binding ) if @ctx.lead.leadset.mangle_subject || @ctx.email_template.mangle_subject ## From: https://www.ascii-code.com/ n1 = 33 n2 = 64 ch1 = ( rand(n2-n1)+n1 ).chr # ('UTF-8') ch2 = ( rand(n2-n1)+n1 ).chr if rendered_subject.last.ord >= n1 && rendered_subject.last.ord <= n2 space_idx = rendered_subject.rindex(/ /) rendered_subject = rendered_subject[0...space_idx] end rendered_subject = "#{rendered_subject} #{ ch1 }#{ ch2 }" end @ctx.update({ rendered_str: rendered_str, sent_at: Time.now, rendered_subject: rendered_subject, }) profile = Wco::Profile.find_by email: @ctx.from_email = { address: profile.smtp_host, authentication: 'login', enable_starttls_auto: true, password: profile.smtp_password, port: profile.smtp_port, user_name: profile.smtp_username, }; mail( from: @ctx.from_email, to: @ctx.to_email, cc: @ctx.cc, bcc: @ctx.from_email, # DEFAULT_BCC, subject: rendered_subject, body: rendered_str, content_type: "text/html", delivery_method_options: ) end |
#shared_galleries(profiles, gallery) ⇒ Object
105 106 107 108 109 110 111 112 113 114 |
# File 'app/mailers/wco_email/application_mailer.rb', line 105 def shared_galleries profiles, gallery return if profiles.count == 0 @gallery = gallery @domain = Rails.application.config.action_mailer.[:host] @galleries_path = IshManager::Engine.routes.url_helpers.galleries_path @gallery_path = IshManager::Engine.routes.url_helpers.gallery_path(@gallery.slug) mail( :to => '314658@gmail.com', :bcc => profiles.map { |p| p.email }, :subject => 'You got new shared galleries on pi manager' ) end |
#stock_alert(watch_id) ⇒ Object
116 117 118 119 120 121 122 |
# File 'app/mailers/wco_email/application_mailer.rb', line 116 def stock_alert watch_id @watch = Iro::OptionWatch.find watch_id mail({ to: @watch.profile.email, subject: "Iro Watch Alert :: #{@watch.ticker} is #{@watch.direction} #{@watch.mark}." }) end |
#test_email ⇒ Object
124 125 126 |
# File 'app/mailers/wco_email/application_mailer.rb', line 124 def test_email mail( to: DEFAULT_RECIPIENT, subject: "Test email at #{Time.now}" ) end |