0

I want to send a mail via Groovy. I tried with the mail command in mac and its working fine.

This is the command I'm using :

echo $message | mail -s "subject" [email protected]

Where message is a gstring :

def message = """ Hi 

 Test mail """

The problem I'm facing is; when the mail is delivered the message is coming in a single line rather than the way it stored.

Where I'm making the mistake??

2
  • How are you running that line of shell scripting? Commented Nov 25, 2013 at 14:12
  • Similar to your answer stackoverflow.com/questions/8049854/… Commented Nov 25, 2013 at 14:15

1 Answer 1

1

You can do:

[ '/bin/bash', '-c', "echo '$msg' | mail -s 'subject' [email protected]" ].execute().waitFor()

ie: wrap the msg in quotes '

Obviously, any quotes in msg will need to be escaped, or this will fail.

A more resilient option would be to use java mail

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.