0

I have a requirement to generate report and send them to a distribution list.
The problem I am facing is when sending out the email using mailx. The email address (DL) we have is starting with # and because of this it's not recognizing the email and throwing the below error.

Error:

Send options without primary recipient specified

When I try to put the email under "" then no email has been send out.

I did a echo and could see $RECIPIENT has the full email address as the value.

RECIPIENT=$RECIPIENT"#[email protected]";

echo "$BODY" | mailx -r "$SENDER" -s "$SUBJECT" -a "$ODFILENAME" -a "$LOFILENAME" "$RECIPIENT"

OS is Linux.

How can I solve it?

5
  • $RECIPIENT would start with a # if it is unset or empty when entering this code fragment. Commented Apr 25, 2018 at 6:36
  • Could you please elaborate? when I did the echo to check teh values in $RECIPIENT it has the whole email address "#[email protected]" as expected. Commented Apr 25, 2018 at 6:42
  • Sorry, I thought the question was about why the mail address started with a #. If that is indeed the correct address, then why do you append it to the RECIPIENT variable? Does that variable contain anything since previously? It should not contain backslashes or newlines. Commented Apr 25, 2018 at 6:55
  • ok, may not be the correct way. I am setting up the value for RECIPIENT variable. The problem is mailx command is NOT working with this email address, when I test it with any other address that does not start with hash it works fine. Is there a way to overcome this issue? Commented Apr 25, 2018 at 7:06
  • Have you tried putting the address in quotes?  Note that this requires escaping ($RECIPIENT\"#[email protected]\") or the use of nested quotes ($RECIPIENT'"#[email protected]"'). Commented Feb 20, 2019 at 18:15

2 Answers 2

1

Use \#[email protected]; this would solve the issue.

1
  • 1
    How would it solve the issue? Also, what issue would it solve? Commented Feb 20, 2019 at 17:23
-1

If I understood correctly, your first character # is making you problems here. So I would suggest you to use cut command to remove the fist character

CLEAN_EMAIL=$(echo $RECIPIENT | cut -c 2-); echo $CLEAN_EMAIL

5
  • As far as I understand, the address, including the initial #, is the correct address. Commented Apr 25, 2018 at 8:33
  • Yes, thats correct. The correct email address is including the #. i.e. #[email protected]. I have to use this as it is when sending the email. Commented Apr 25, 2018 at 8:49
  • so you need to eliminate # sign in order to work with mailx , as you mention in the comment above right? when I test it with any other address that does not start with hash it works fine Commented Apr 25, 2018 at 8:56
  • No, I do not want to eliminate hash # symbol. If I did it will be an invalid email address. The correct email address is #[email protected]. i.e. with ahsh symbol. I think since the email having # I am getting issues when sending out the email. I would like to know how to handle this issue and use this email in mailx to send out the emails. Commented Apr 25, 2018 at 9:07
  • That is strange, when I execute this echo "BODY" | mailx -r "SENDER" -s "SUBJECT" -a "/tmp/traffic_ifeth0" "#[email protected]" I get no error. Without hash, I am able to receive email and attachment. Commented Apr 25, 2018 at 10:09

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.