-4

My sample data File is

$ cat /fullpath/a.csv
a@gmail.com, Amit Singh
k@gmail.com, Km Singh

I am using script.sh

   #!/bin/bash

while IFS= read -r line
do

email=$(echo $line | awk -F, '{print $1 }')
name=$(echo $line | awk -F, '{print $2 }')

echo | mailx -v -s "Helo $name" -S smtp-use-starttls -S ssl-verify=ignore -S smtp-auth=login -S smtp=smtp://smtp.gmail.com:587 -S from="xxxx@gmail.com(John Smith)" -S smtp-auth-user=xxxx@gmail.com -S  smtp-auth-password=xxxxpassword## -S ssl-verify=ignore -S nss-config-dir=~/.certs "$name<$email>" 

done < /fullpath/a.csv

When I send an email, it goes well. but won't pick receiver name in "$name<$email>"

how is the correct syntax of receiver name there?

Pro Coder
  • 71
  • 6
  • when i try to edit with full error it show "It looks like your post is mostly code; please add some more details." – Pro Coder Dec 28 '19 at 17:54
  • last few lines of error > 250 2.1.0 OK g25sm13460353otr.8 - gsmtp >>> RCPT TO: 553 5.1.3 The recipient address is not a valid RFC-5321 address. g25sm13460353otr.8 - gsmtp smtp-server: 553 5.1.3 The recipient address is not a valid RFC-5321 address. g25sm13460353otr.8 - gsmtp "/home/whoisdat/dead.letter" 28/863 . . . message not sent. – Pro Coder Dec 28 '19 at 17:56
  • Your example doesn't contain Amit anywhere so it's hard for us to connect the dots. It certainly looks like your question is also not reproducible with the details you provided, which is another common reason for posts to get closed. – tripleee Dec 29 '19 at 09:04
  • You'll want to add enough text to explain the code you add to balance things up. In the worst case, you can store a lengthy error message on an external site like pastebin.com and explain that your low reputation prevents you from providing it within the question itself. – tripleee Dec 29 '19 at 09:06
  • But update the original, not this duplicate. – tripleee Dec 29 '19 at 09:07
  • 1
    Also, probably spend more time in the [help] to understand how this site works, how regular users like yourself have the same mandate as high-rep users like Ed and myself to help moderate this site, how closing as a duplicate was exactly the right course of action here, and how to properly seek corrections if you genuinely thought a mistake had been made. (Hint: ad hominem attacks are not it.) – tripleee Dec 29 '19 at 09:25

2 Answers2

1

The correct format would have a space between the real name and the email terminus; but I don't think mailx will accept this on the command line, or at the very least not expose it in the To: header. Try this instead:

echo "To: $name <$email>" |
mailx ... options ... "$email"

You are using IFS anyway, so why not use it fully?

while IFS=, read -r email name; do ...

Perhaps a better design still would be to not use a comma as separator.

tripleee
  • 175,061
  • 34
  • 275
  • 318
  • it show To: contains invalid character ':' – Pro Coder Dec 28 '19 at 17:05
  • when i remove : it show >>> RCPT TO: 553 5.1.3 The recipient address is not a valid RFC-5321 address. r17sm13058697otq.70 - gsmtp – Pro Coder Dec 28 '19 at 17:06
  • Then `$email` somehow ended up not containing the actual email address. Your example doesn't contain "Amit" but I guess you have an entry like `Amit, amit@gmail.com` with the fields in the wrong order; or you somehow got the variables mixed up. – tripleee Dec 29 '19 at 09:02
0

You have commented out the part of the command containing the receiver name, using '##':

-S  smtp-auth-password=xxxxpassword##

If you need to have your password ending in #, put the argument in quotes.

Also, I would put a space after the personal name, i.e. $name <$email>. I am not sure whether this is required or just commonly done this way.

Aside from this, I suggest that while testing your script, you run it with set -x turned on, so that you see exactly what will be passed to mailx. This will also catch cases where $email is incorrect.

user1934428
  • 19,864
  • 7
  • 42
  • 87