1

I'm trying to send an email from the command line with Ruby code on a Sinatra server. On the command line, I've successfully used:

smtpfree_mail.pl -from noreply@website.com -to testemail@gmail.com -subject "test msg" -body "message body" 

so could I possibly use:

%x(smtpfree_mail.pl -from noreply@website.com -to testemail@gmail.com -subject "test msg" -body "message body")

as suggested by this answer? I want to later input several variables into the email body.

Community
  • 1
  • 1
Charles Murray
  • 383
  • 3
  • 8
  • 20
  • Running arbitrary shell commands with user input is asking for trouble. Be **extremely** careful when doing this. – tadman Nov 26 '14 at 00:21

3 Answers3

2

Why don't you use mail sending gems such as mail or pony? You can do it natively just right from your Sinatra application code. I didn't suggest ActionMailer since it huge, these gems above are very small and handy.

sashaegorov
  • 1,821
  • 20
  • 26
1

Can you run other programs from Ruby? Yes, you can. As you have seen from the question you have linked to.

Having no idea what smptfree_mail.pl holds, it is perhaps not possible for you to later input several variables into the email body. Assuming that it is sending that e-mail out, I would suppose that changing the content of the e-mail body would be questionable, as it would be too late, the next mail server would have it and it would be out of your hands.

However, it would be possible for you to change the body of the message earlier, not later, and easily so, as you have the template code in your question that sets the stage.

vgoff
  • 10,980
  • 3
  • 38
  • 56
1

you can use Net::SMTP its much more secure and you can pass variables please check this in rubydocs.

A working example/tutorial can be found here

pshoukry
  • 755
  • 5
  • 14