-1

We have created a UNIX program which is used to send mails. In that program we are fetching the mail subject and body based on user inputs (through Oracle Concurrent Program)

For example:

The complete user inputs of concurrent program are storing in $1 variable which is as below:

XX_EMAIL_FILES FCP_REQID=9614696 FCP_LOGIN="APPS/sup12" \
FCP_USERID=5667 \
FCP_USERNAME="SRI" \
FCP_PRINTER="noprint" \
FCP_SAVE_OUT=Y \
FCP_NUM_COPIES=1 \
"9614556_SUP12_XX_Workflow_Stuck_AP_Invoices.csv" \
"/tmp_mnt2/attachments" \
"Sri.B@xx.com" \
"This is the subject for the mail" \
"PFA for the list of Invoices that are stuck in workflow."

Here, subject for mail is This is the subject for the mail which we are storing in variable SUB and body for mail is PFA for the list of Invoices that are stuck in workflow. which we are storing in another variable FCP_BODY.

Now, I wrote as below to send mail

echo "Hello,
${FCP_BODY}
Thanks,
Bommi
"| mailx -s $SUB

But, in the mail I received, the body is coming properly, but subject is coming just This.

Can anyone please help me on how to fetch the complete subject to send mail?

  • Since $SUB variable contains multiple words you should quote the variable with | mailx -s "$SUB" – user000001 Aug 14 at 11:51
  • 1
  • also, if you are sending attachments in the message (e.g. a .CSV file), you probably want to use a tool that knows how to do mime attachments correctly, rather than mailx. e.g. mime-construct - this is available packaged for debian, and probably other distros too. – cas Aug 14 at 14:44
2

You need to quote the variable $SUB:

... mailx -s "$SUB"

Explanation: A variable containing spaces is going to be subject to word splitting. That is, if you have the command

mailx -s $SUB

and the variable $SUB contains the string "This is the subject for the mail"

the previous command gets expanded as

mailx -s This is the subject for the mail

i.e. the -s flag (Subject) gets only the argument This, and the rest of the words are passed as other arguments, and (in most cases) handled like garbage.

Instead,

mailx -s "$SUB"

gets expanded as

mailx -s "This is the subject for the mail"

which is what you wanted.


Related questions and answers:

  • Hi, Thank you :) It really helped and resolved the issue Regards, – Bommi Aug 16 at 7:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.