Class: Newman::Mailer
- Inherits:
-
Object
- Object
- Newman::Mailer
- Defined in:
- lib/newman/mailer.rb
Instance Method Summary collapse
-
#deliver_message(*a, &b) ⇒ Object
‘Newman::Mailer#deliver_message` is used to construct and immediately deliver a message using the delivery settings that were set up at initialization time.
-
#initialize(settings) ⇒ Mailer
constructor
To initialize a ‘Newman::Mailer` object, a settings object must be provided, i.e:.
-
#messages ⇒ Object
‘Newman::Mailer#messages` is used to retrieve all messages currently in the inbox and then delete them from the server.
-
#new_message(*a, &b) ⇒ Object
‘Newman::Mailer#new_message` is used to construct a new `Mail::Message` object, with the delivery settings that were set up at initialization time.
Constructor Details
#initialize(settings) ⇒ Mailer
To initialize a ‘Newman::Mailer` object, a settings object must be provided, i.e:
settings = Newman::Settings.from_file('config/environment.rb')
mailer = Newman::Mailer.new(settings)
This is done automatically for you by ‘Newman::Server.simple`, but must be done manually if you are creating a `Newman::Server` instance from scratch.
Currently, not all of the settings supported by the mail gem are mapped by Newman. This is by design, to limit the amount of configuration options need to think about. However, if this is causing you a problem, please [file an issue](github.com/mendicant-university/newman/issues).
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/newman/mailer.rb', line 34 def initialize(settings) imap = settings.imap smtp = settings.smtp self.retriever_settings = { :address => imap.address, :user_name => imap.user, :password => imap.password, :enable_ssl => imap.ssl_enabled || false, :port => imap.port } self.delivery_settings = { :address => smtp.address, :user_name => smtp.user, :password => smtp.password, :authentication => :plain, :enable_starttls_auto => smtp.starttls_enabled || false, :port => smtp.port } end |
Instance Method Details
#deliver_message(*a, &b) ⇒ Object
‘Newman::Mailer#deliver_message` is used to construct and immediately deliver a message using the delivery settings that were set up at initialization time.
88 89 90 |
# File 'lib/newman/mailer.rb', line 88 def (*a, &b) (*a, &b).deliver end |
#messages ⇒ Object
‘Newman::Mailer#messages` is used to retrieve all messages currently in the inbox and then delete them from the server. This method returns an array of `Mail::Message` objects if any messages were found, and returns an empty array otherwise.
63 64 65 |
# File 'lib/newman/mailer.rb', line 63 def Mail::IMAP.new(retriever_settings).all(:delete_after_find => true) end |
#new_message(*a, &b) ⇒ Object
‘Newman::Mailer#new_message` is used to construct a new `Mail::Message` object, with the delivery settings that were set up at initialization time. This method passes all its arguments on to `Mail.new`, so be sure to refer to the [mail gem’s documentation](github.com/mikel/mail) for details.
75 76 77 78 79 80 |
# File 'lib/newman/mailer.rb', line 75 def (*a, &b) msg = Mail.new(*a, &b) msg.delivery_method(:smtp, delivery_settings) msg end |