1

I am trying to send mail through BCC,CC and TO list. CC and TO are working fine but getting error from BCC as mailx: illegal option -- b

Here is my syntax

(echo "$MSG_BODY";)|mailx -r "abc@abc.com" -s "$MSG_SUB" -b $BCC_LIST -c $CC_LIST $TO_LIST 

Please help me out.

  • [How can I bcc with mailx?](https://unix.stackexchange.com/q/97067/44425), [Sending email with CC BCC and sender's address in unix mailx](https://stackoverflow.com/q/10099854/995714) – phuclv Jun 13 '18 at 07:13

2 Answers2

2

If you have sendmail utility, use can use it to send the mails through BCC:

(
echo "MIME-Version: 1.0
From: abc@abc.com
To: $TO_LIST
Cc: $CC_LIST
Bcc: $BCC_LIST
Subject: $MSG_SUB
Content-Type: text/html
"
echo "$MSG_BODY"
) | /usr/sbin/sendmail -t

Please let me know if it helps.

User123
  • 1,498
  • 2
  • 12
  • 26
  • Output is coming like "No recipient addresses found in header" –  Jun 13 '18 at 08:54
  • Have you defined the variables: `TO_LIST`,`CC_LIST`,`BCC_LIST` etc in your script? – User123 Jun 13 '18 at 08:57
  • `TO_LIST=`db2 -x "query"` `CC_LIST=`db2 -x "query"`; `BCC_LIST='dipak.das@abc.com' `MSG_SUB="Subject" `MSG_BODY="Body" `(echo "MIME-Version: 1.0 From: CU@abc.com To: $TO_LIST Cc: $CC_LIST Bcc: $BCC_LIST Subject: $MSG_SUB Content-Type: text/html" echo "$MSG_BODY" ) `| /usr/sbin/sendmail -t –  Jun 13 '18 at 09:25
  • have you checked if `sendmail` is configured in your unix system?Which OS you are using? – User123 Jun 13 '18 at 09:31
  • using `AIX 7.2` and `/usr/sbin/sendmail` permission has been denied could not able to read the file. –  Jun 13 '18 at 09:36
  • use `which sendmail` command to check if the `sendmail` is correctly configured in your system. As per the error and above comments, it seems it's not configured, so need to try a different method. – User123 Jun 13 '18 at 09:40
1

mail (GNU Mailutils) 3.7 has an append option to add headers and values directly without piping them in. Just add the headers you need there, e.g. bcc:

echo "Just testing my sendmail" | mail -s "Sendmail test" test@to.com --append=Bcc:test@bcc.com

poleguy
  • 523
  • 7
  • 11