Class: Nuntius::SmtpMailProvider
- Inherits:
-
BaseProvider
- Object
- BaseProvider
- Nuntius::SmtpMailProvider
- Defined in:
- app/providers/nuntius/smtp_mail_provider.rb
Instance Attribute Summary
Attributes inherited from BaseProvider
Instance Method Summary collapse
Methods inherited from BaseProvider
all_settings, #callback, class_from_name, #initialize, #name, #refresh, setting_reader, states, transport
Constructor Details
This class inherits a constructor from Nuntius::BaseProvider
Instance Method Details
#block ⇒ Object
69 70 71 72 |
# File 'app/providers/nuntius/smtp_mail_provider.rb', line 69 def block .status = 'blocked' end |
#deliver ⇒ Object
16 17 18 19 20 21 22 23 24 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 58 59 60 61 62 63 64 65 66 67 |
# File 'app/providers/nuntius/smtp_mail_provider.rb', line 16 def deliver return block unless MailAllowList.new(settings[:allow_list]).allowed?(.to) return block if Nuntius::Message.where(status: %w[complaint bounced], to: .to).count >= 1 mail = if .from.present? Mail.new(sender: from_header, from: .from) else Mail.new(from: from_header) end if Rails.env.test? mail.delivery_method :test else mail.delivery_method :smtp, address: host, port: port, user_name: username, password: password, return_response: true end mail.to = .to mail.subject = .subject mail.part content_type: 'multipart/alternative' do |p| p.text_part = Mail::Part.new( body: .text, content_type: 'text/plain', charset: 'UTF-8' ) if .html.present? .html = .html.gsub('%7B%7Bmessage_url%7D%7D') { () } p.html_part = Mail::Part.new( body: .html, content_type: 'text/html', charset: 'UTF-8' ) end end ..each do || mail.[.filename.to_s] = { mime_type: .content_type, content: .download } end response = mail.deliver! .provider_id = mail. .status = 'undelivered' .status = 'sent' if Rails.env.test? ? true : response.success? .last_sent_at = Time.zone.now if .sent? end |