send email to email id which is having # symbol

Hi,

I have one requirement to send email to email id which is having # ( in the begining of the email id).

I'm using mailx command to send an email. But not receiving those emails, but email status is showing email sent successful.

Code which i'm using is :

cat  file1.txt | mailx -s 'Testing mail with # in begining without quotes' testing1@hostname,#testing2@hostname -- -f no-reply@motorola.com

If I enter email address within single quotes or double quotes also, not working properly, says email sent successfully.

one more example,

Even If I place # email id as first email id, will throw below error,
You must specify direct recipients with -s, -c, or -b.

After that, I have enter email address within single quotes or double quotes also, i'm not receiving the email. but its says email sent successfully.

Can you please help me to resolve this issue?
Because I got the requirement which email id has the # symbol.

Regards
Latika

try assign the email id's to a variable and then use that variable in the mailx syntax ..

Hi Jayan,

I'm using below code to send an email, getting status as email sent successfully, but not reciving the email in inbox.

$cmd="cat file1.txt";
$emailsubject ="Testing script mail # in begining with dobule quotes";
$emailaddress="#name\@hostname,name2\@hostname,name3\@hostname";
$from_address="no-reply\@hostname";
# double quotes
$cmd = $cmd . "|" ."mailx -s '$emailsubject' \"$emailaddress\" -- -f $from_address" ;
# single quotes
#$cmd = $cmd . "|" ."mailx -s '$emailsubject' \'$emailaddress\' -- -f $from_address" ;
print "Command is : $cmd\n";
if(system($cmd)){
        print "Email sent Failed\n";
}else {
        print "Email sent successfuly\n";
}
 
#!/usr/bin/perl
use MIME::Lite;
$msg = MIME::Lite->new(
        From     => 'Sender Name <sender@abc.com>',
        To       => 'recipient@abc.com,#two@abc.com',
        Subject  => 'Accepted!',
        Data     => "Hi This is the Test Message!"
);
$msg->send;