Class: Tolliver::Services::Methods::Email

Inherits:
Object
  • Object
show all
Defined in:
lib/tolliver/services/methods/email.rb,
lib/tolliver/services/methods/email/smtp.rb,
lib/tolliver/services/methods/email/mailgun.rb

Defined Under Namespace

Classes: Mailgun, Smtp

Instance Method Summary collapse

Instance Method Details

#deliver(notification_receiver) ⇒ Object



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 'lib/tolliver/services/methods/email.rb', line 34

def deliver(notification_receiver)
  return false if provider.nil?

  # Prepare notification
  notification = notification_receiver.notification_delivery.notification

  # Send email
  begin
    provider.deliver(notification, notification_receiver)
    notification_receiver.status = 'sent'
  #rescue Net::SMTPFatalError, Net::SMTPSyntaxError
  rescue StandardError => e
    notification_receiver.status = 'error'
    notification_receiver.error_message = e.message
  end

  # Mark as sent
  notification_receiver.sent_at = Time.current

  # Save
  notification_receiver.save

  true
end

#is_notification_delivery_valid?(notification_delivery) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
# File 'lib/tolliver/services/methods/email.rb', line 23

def is_notification_delivery_valid?(notification_delivery)
  return false if !notification_delivery.sender_email.blank? && !(notification_delivery.sender_email =~ URI::MailTo::EMAIL_REGEXP)
  true
end

#is_notification_receiver_valid?(notification_receiver) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
# File 'lib/tolliver/services/methods/email.rb', line 28

def is_notification_receiver_valid?(notification_receiver)
  return false if notification_receiver.receiver_email.blank?
  return false unless notification_receiver.receiver_email =~ URI::MailTo::EMAIL_REGEXP
  true
end

#is_notification_valid?(notification) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
20
21
# File 'lib/tolliver/services/methods/email.rb', line 17

def is_notification_valid?(notification)
  return false if notification.subject.blank?
  return false if notification.message.blank?
  true
end