Class: MacMailer::Message
- Inherits:
-
Object
- Object
- MacMailer::Message
- Defined in:
- lib/macmailer.rb
Overview
Message is the main MacMailer class.
Instance Method Summary collapse
-
#create(send = false) ⇒ Object
Creates an email, based on ‘@props`, using AppleScript.
-
#initialize(props = {}) ⇒ Message
constructor
Creates a MacMailer::Message instance.
-
#send ⇒ Object
Convenience method to create and send the message.
-
#show ⇒ Object
Brings Mail.app to the front, using AppleScript.
Constructor Details
#initialize(props = {}) ⇒ Message
Creates a MacMailer::Message instance. ‘props` can be left blank for a blank message, but you’ll probably want to pass along some details. Valid keys for ‘props` include:
:subject => String :body => String :recipients => Array (of hashes)
Each hash in :recipients supports the following keys:
:address => String :name => String :type => :to, :cc, or :bcc
21 22 23 |
# File 'lib/macmailer.rb', line 21 def initialize (props={}) @props = props end |
Instance Method Details
#create(send = false) ⇒ Object
Creates an email, based on ‘@props`, using AppleScript. Does not send the email unless the optional `send` parameter is set to `true`.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/macmailer.rb', line 28 def create (send=false) script = <<-SCRIPT tell application "Mail" set msg to make new outgoing message with properties {subject:#{(@props[:subject] || "").dump}, content:#{(@props[:body] || "").dump}, visible:true} tell msg #{(@props[:recipients] || []).map {|x| _make_recipient(x[:address], x[:name], x[:type]) }.join("\n") } #{send ? "send" : ""} end tell end tell SCRIPT @shell_response = `/usr/bin/osascript > /dev/null <<MACMAILERSCRIPT #{script} \nMACMAILERSCRIPT` self end |
#send ⇒ Object
Convenience method to create and send the message.
45 46 47 |
# File 'lib/macmailer.rb', line 45 def send self.create(send=true) end |
#show ⇒ Object
Brings Mail.app to the front, using AppleScript.
50 51 52 53 54 55 56 57 |
# File 'lib/macmailer.rb', line 50 def show `/usr/bin/osascript > /dev/null <<MACMAILERSCRIPT tell application "Mail" activate end tell \nMACMAILERSCRIPT` self end |