Question

I want to actually call the following in Ruby

echo "<html><body><b>BOLD</b></body></html>" | mutt -e "set content_type=text/html" -s "HTML content"  -- anushka.misra2@gmail.com

I was successfully able to do it in Ruby with system() method:

system 'echo "<html><body><b>BOLD</b></body></html>" | mutt -e "set content_type=text/html" -s "HTML content"  -- anushka.misra2@gmail.com'

Now, I want email to be a variable:

email = anushka.misra2@gmail.com
system 'echo "<html><body><b>BOLD</b></body></html>" | mutt -e "set content_type=text/html" -s "HTML content"  -- $email'

But this fails as it doesn't evaluate email variable. How do I fix it?

Was it helpful?

Solution

system %Q{echo "<html><body><b>BOLD</b></body></html>" | mutt -e "set content_type=text/html" -s "HTML content"  -- #{email}}

#{foo} is the Ruby way to add a value into a string. #{foo} is only evaluated in strings with " (not '). Where %Q{} does the same, but you do not have to escape " inside the string.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top