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


/ Published in: Ruby
Save to your folder(s)



Copy this code and paste it in your HTML
  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

You need to login to post a comment.