Using uuencode to attach multiple attachments from a variable to an e-mail and send using sendmail

南笙酒味 提交于 2019-12-11 09:45:49

问题


I have a script that currently does:

cat $body | uuencode $attachment $attachment | sendmail $sender -t

What should I adjust so that $attachment could be multiple attachments? I have come up with the below but it doesn't look correct?

cat $body |
for i in $attachments 
do
uuencode $i $i
done
| sendmail $sender -t

回答1:


Typically, you don't want to store a list of file names in a parameter. With default IFS, spaces embedded within file names will give rise to problems. Instead, declare an array with files

a=(file1 file2 file3 file4)
(for file in "${a[@]}"; do uuencode "$file" "$(basename "$file")"; done) |
 sendmail $sender -t



回答2:


Try the following script:

# specify list of email recipients
recipients=...
# specify envelope sender address
sender=...
( 
  cat $body
  for i in $attachments 
  do
    uuencode $i $i
  done
) | sendmail -f$sender -i -- $recipients
  • $body file must contain message headers (e.g. Subject:) separated by an empty line from message body
  • IMHO it is a better/safer style to specify recipients via command line instead of making sendmail extract them from headers.



回答3:


FILES="/rollovers/DailyCadRpt.* /rollovers/DailyFireRpt.*"

(for f in $FILES ; do uuencode "$f" "$f" ; done ) | mail -s "Subject" recipient_email@domain.com

The above works in AIX 6.1 for wildcards. But, you must use the 10-pad asterisk. The asterisk above the number eight does not work in AIX. Also, this does not have any body text. But that is done as in the other examples. You may add more files by using a space as the separator, as in my example. Also, you cannot use Daily* with either asterisk. AIX just won't do it. The asterisk must come after a period in the file name. Our reports have the date added to the report name separated by a period. It preserves our archival naming pattern and grabs it every day without needing a specific file name.



来源:https://stackoverflow.com/questions/19940292/using-uuencode-to-attach-multiple-attachments-from-a-variable-to-an-e-mail-and-s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!