0

I have written a ruby cli script which takes a CSV and generates a PDF report, based on said CSV. I'm fairly new to Ruby, so while it's probably not the greatest code, I'm pretty proud of what I've made.

At any rate, what I would really like to do now, is make my script email said PDF as an attachment. I'm sure there is a library that understands SMTP and can send this on my behalf, but I would like to modify the email body, and review the attachments before sending. So it seems like the simplest thing would be to have the script start a new email in my system default mail client, providing the recipient, subject, and boiler plate text, and attaching the generated file, kind of like a mailto: link in a web page (does mailto support attachments?).

Seems like there could be a system command that does this, completely unrelated to Ruby, which I could have my Ruby script call. That would be fine. If it's platform dependent, I'm on OSX, but I move around, so am interested in Windows and Linux solutions, too.

I guess plan B would be a way to jam a simple CLI editor into my Ruby script, to let me edit the email text, and then use an SMTP library to send the email. That seems harder, unless it's already been done.

eimajenthat
  • 1,338
  • 3
  • 15
  • 33
  • Something ike this: http://support.microsoft.com/kb/287573 , but compatible with OSX. – eimajenthat Mar 13 '13 at 14:34
  • Pony is the ruby gem you want for the smtp email. If I were you I would hold the body text in a string and then modify that string before sending. – Xwris Stoixeia Mar 13 '13 at 15:44
  • Thanks @XwrisStoixeia. That may be the better solution. Editing the message string seems a little tricky, though. I found this: http://stackoverflow.com/questions/4026546/ruby-console-application-using-text-editor but it looks a little complicated. – eimajenthat Mar 13 '13 at 16:58
  • http://stackoverflow.com/questions/8463986/how-to-do-a-textbox-in-terminal-ruby-applications another option – eimajenthat Mar 13 '13 at 17:03

1 Answers1

0

Actually you can execute any ruby file from command-line interface (CLI) using console_runner gem. If you already have written code you can run it from command line. All you need is to add annotations (YARD-like syntax) to your Ruby code and then execute it from command line:

$ c_run /path/your_file.rb say_hello

/path/your_file.rb:

# @runnable
class MyClass

    # @runnable
    def say_hello
      puts 'Hello!'
    end

end
Yuri Karpovich
  • 382
  • 4
  • 10
  • Wow, this is a blast from the past. Thanks for the answer. That's an interesting library, but I don't think it accomplishes what I was trying to do here. I wanted my ruby script to open a mail client (like a mailto: link would do), and create a boilerplate email for me to finish and send. This looks pretty different. – eimajenthat Apr 30 '19 at 20:24