嗨,我有这个代码的问题:
# up here there's more code
echo "Password changed" $(date) > lez.txt
curl -n --ssl-reqd --mail-from "[email protected]" --mail-rcpt "my mail" -T lez.txt --url smtps://smtp.gmail.com:465 --user "[email protected]:password"
如果我运行脚本,我只收到一封空邮件,但如果我手动执行此操作,我会收到邮件。谢谢。
看起来它有问题找到文件内容。如何使用here-string来避免写文件呢?将您的代码更改为:
curl -n --ssl-reqd --mail-from "[email protected]" --mail-rcpt "my mail" -T - --url smtps://smtp.gmail.com:465 --user "[email protected]:password" <<<"Password changed $(date)"
注意echo
语句删除,行末尾的here-string和-T -
从stdin获取文件。
cURL期望要发送的文件在第1行上有一个空行
下面的脚本将为您完成
##!/bin/sh
# USAGE
#
# sh emailfile.sh examplefile.log
file="$1"
echo "" > temp | cat "$1" >> temp && mv temp "$1"
wait
curl --url "smtps://smtp.mail.yahoo.com:465" \
--mail-from "[email protected]" \
--mail-rcpt "[email protected]" \
--user "[email protected]:EmailAccountPassword" \
-T - --silent < "$file"
wait