SWAKSまたは他のプログラムを使用してbashと電子メールを使用して複数のファイルを添付する

SWAKSまたは他のプログラムを使用してbashと電子メールを使用して複数のファイルを添付する

私は試みる:

  1. 1つのメールに複数のファイルを添付してください。
  2. Gmailアカウントを使用してメールを送信し、件名ヘッダーに現在の日付と時刻を含めます。

複数の電子メールを生成したくないため、forループに問題があります。私はちょうどすべての添付ファイルを含む電子メールを書いています。そしてタイトル行に現在の日付と時刻を使用してください。

#!/bin/bash
# to run type "bash email_live_listing.sh"

dt_now_start=`date +"%Y-%m-%d %T"`
fn_dt_now_start=`date '+%Y_%m_%d__%H_%M_%S'`; #use to generate file name with date
currentdir="$(pwd)" #get current directory


ls $currentdir/us*.pdf -tp | grep -v '/$fn_pdf' #place files into variable

echo "$fn_pdf"

ITER=0
for t in ${fn_pdf[@]}; do
swaks --to [email protected] -s smtp.gmail.com:587 -tls -au [email protected] -ap password --header "Subject: Updated file ${fn_dt_now_start}" --body "Email Text" --attach-type ./${fn_pdf} -S 2
let ITER+=1 #increment number
done

PS:私はUbuntuを使っていますワックスコンパクトで軽量で、ラズベリーパイで実行されますしかし、他のオプションを試してみたいと思います。

ベストアンサー1

ここで私が始めた問題を他の人が解決するのに役立つbashスクリプトがあります。

    #!/bin/bash
    currentdir="$(pwd)" #get current directory
    fn_dt_now_start=`date '+%Y_%m_%d__%H_%M_%S'`; #use to generate date time

    fn_txt=$(ls $currentdir/*.txt) #place txt files found into a variable

    for t in ${fn_txt[@]}; do
        attach_files="${attach_files} --attach-type ${t}" #will build list of files to attach
    done

    swaks --to [email protected] -s smtp.gmail.com:587 -tls -au [email protected] -ap <email_sending_from_password>] --header "Subject: Listings - ${fn_dt_now_start}" --body "Listings Email Text" ${attach_files} -S 2

おすすめ記事