Class: Messenger::Email
- Inherits:
-
Object
- Object
- Messenger::Email
- Defined in:
- lib/messenger/email.rb
Class Method Summary collapse
-
.deliver(url, message, options = {}) ⇒ Object
URL format: [email protected].
- .obfuscate(url) ⇒ Object
- .valid_url?(url) ⇒ Boolean
Class Method Details
.deliver(url, message, options = {}) ⇒ Object
URL format:
mailto:[email protected]
Options:
:email_from => Who the email is from
:email_subject => The subject of the email
15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/messenger/email.rb', line 15 def self.deliver(url, , ={}) raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url) mail = Mail.new do from [:email_from] to url.sub(/\Amailto:/, '') subject [:email_subject] body end mail.deliver! Messenger::Result.new(true, nil) rescue Errno::ECONNREFUSED, Errno::EAFNOSUPPORT => e Messenger::Result.new(false, e) end |
.obfuscate(url) ⇒ Object
29 30 31 32 |
# File 'lib/messenger/email.rb', line 29 def self.obfuscate(url) raise Messenger::URLError, "The URL provided is invalid" unless valid_url?(url) url end |
.valid_url?(url) ⇒ Boolean
5 6 7 |
# File 'lib/messenger/email.rb', line 5 def self.valid_url?(url) !!url.match(/\A(mailto:)?[^@]+@.*\Z/) end |