如何在mailx中插入名称字段 [英] How to insert name field in mailx
问题描述
我的示例数据文件是
$ cat /fullpath/myfile.csv
a@gmail.com, A Singh
k@gmail.com, K Singh
我正在使用script.sh
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>
将其选择名称(A Singh
)作为电子邮件并说出无效的电子邮件.如果我使用收件人",则选择收件人"作为电子邮件.即certs
代码图片后第1位出现的任何内容(将其作为电子邮件发送).
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.
推荐答案
According to the standard documentation, mailx does not seem to support the -S option, but some systems may add this option.
我建议您使用 GNU Mailutils .
要指定"FROM"的名称和地址,可以使用"-a"选项.
To specify a "FROM" name and address, you can use the "-a" option.
-标头:值
-a header:value
-append = 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
这篇关于如何在mailx中插入名称字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!