-4

My sample data File is

$ cat /fullpath/myfile.csv
a@gmail.com, A Singh
k@gmail.com, K 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/myfile.csv

what is the correct syntax of adding receiver name


I am looking for syntax which I am not able to find I tried below

"$name<$email>"
$name<$email>
-S to:"$name<$email>"
-S To:"$name<$email>"
-S To: "$name <$email>"
-S To: $name <$email>

its picking names (A Singh) as email and say invalid email. if i use To, it pick TO as email. i.e. whatever come 1st after certs code pic that as email.

Pro Coder
  • 71
  • 6
  • 3
    `it didn't work` is the worst possible problem description since it provides no information we could use to help you debug your problem. When you drop your car off at the mechanic for repairs you probably don't just say "it didn't work" and walk away so don't do that here either. Tell us **in your question** in what way it "didn't work" - no output, wrong output, core dump, error messages, something else? Run your script through http://shellcheck.net first, though, and fix the problems it tells you about. – Ed Morton Dec 24 '19 at 13:09
  • @EdMorton PS: you can also be nice and say "you miss the output please add and tos link and so on" – Pro Coder Dec 28 '19 at 18:24
  • I rolled back your edit. The proper way to promote this is to improve the question to the point where it is actually answerable. It's probably also a good idea to reduce it to a [mre] because - as you will have noticed by now - tangential issues in your code work as red herrings. Show us exactly what you tried and exactly how it failed; feel free to spin off related questions if it gets too broad, but provide context between related questions with links and explanations of how they interrelate. – tripleee Dec 29 '19 at 08:09
  • Probably indicate which precise `mailx` command you are using; there are three incompatible versions in common use. See also https://stackoverflow.com/a/48588035/874188 (and perhaps tangentially https://stackoverflow.com/a/22308603/874188) – tripleee Dec 29 '19 at 08:21
  • @tripleee , are you suggesting that the method I am using is old and i should use like this? : mailx -a 'From:name@your-domain.com' -s "Subject" my-best-friend@other-domain.com < text.txt – Pro Coder Dec 29 '19 at 08:35

1 Answers1

-1

According to the standard documentation, mailx does not seem to support the -S option, but some systems may add this option.

I recommend you use GNU Mailutils.

To specify a "FROM" name and address, you can use the "-a" option.

-a header:value

--append=header:value

Append the given header to the composed message.

To specify the receiver name and address, just like you did, add name and email to the end of the command will do the work.

#!/bin/bash

while IFS= read -r line
do

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

mail -s "Hello $name" -a "From: John Smith<xxxx@gmail.com>" "$name<$email>"
#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 < ./myfile.csv
  • Thank.. but -S works perfectly fine for me so far... I suppose to use all the option I show in my sample... to pass the validity of my email... (DKIM, DMARC, SPF from gsuite)... – Pro Coder Dec 25 '19 at 12:23