Posted By

bbebop on 03/22/07


Tagged

applescript ruby macosx rb-appscript


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

webstic


Sending Apple Mail with Ruby and rb-appscript instead of Applescript


 / Published in: Ruby
 

  1. require "appscript"
  2. include Appscript
  3.  
  4. def send_email(subject, content, *addresses)
  5. mail = app('Mail')
  6.  
  7. msg = mail.outgoing_messages.end.make(:new => :outgoing_message)
  8.  
  9. # mail.set(msg.visible, :to => true) # by default,
  10. mail.set(msg.subject, :to => subject)
  11. mail.set(msg.content, :to => content)
  12. # mail.set(msg.sender, :to => "[email protected]") # otherwise default email address used
  13.  
  14. addresses.each do |addr|
  15. msg.to_recipients.end.make(:new => :to_recipient, :with_properties => {:address => addr})
  16. end
  17.  
  18. msg.send_
  19. end
  20.  
  21. # send_email("subject goes here", "Hello Cruel World!", "[email protected]") # => true

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: mohamed_3d on October 22, 2010

1.require "appscript"2.include Appscript3. 4.def sendemail(subject, content, *addresses)5. mail = app('Mail')6. 7. msg = mail.outgoingmessages.end.make(:new => :outgoingmessage)8. 9. # mail.set(msg.visible, :to => true) # by default, 10. mail.set(msg.subject, :to => subject)11. mail.set(msg.content, :to => content)12. # mail.set(msg.sender, :to => "[email protected]") # otherwise default email address used13. 14. addresses.each do |addr|15. msg.torecipients.end.make(:new => :torecipient, :withproperties => {:address => addr})16. end17. 18. msg.send_ 19.end20. 21.# send_email("subject goes here", "Hello Cruel

You need to login to post a comment.