我有postfix+dovecot。我想制作可以使用 SMTP 的 bash 脚本。我不想使用sendmail。
是否可以?也许有人有一些代码示例?
男孩,当挑战被抛出时,它总是bash
就在我的头顶上! :-)
#!/bin/sh
function checkStatus {
expect=250
if [ $# -eq 3 ] ; then
expect="${3}"
fi
if [ $1 -ne $expect ] ; then
echo "Error: ${2}"
exit
fi
}
MyHost=`hostname`
read -p "Enter your mail host: " MailHost
MailPort=25
read -p "From: " FromAddr
read -p "To: " ToAddr
read -p "Subject: " Subject
read -p "Message: " Message
exec 3<>/dev/tcp/${MailHost}/${MailPort}
read -u 3 sts line
checkStatus "${sts}" "${line}" 220
echo "HELO ${MyHost}" >&3
read -u 3 sts line
checkStatus "$sts" "$line"
echo "MAIL FROM: ${FromAddr}" >&3
read -u 3 sts line
checkStatus "$sts" "$line"
echo "RCPT TO: ${ToAddr}" >&3
read -u 3 sts line
checkStatus "$sts" "$line"
echo "DATA" >&3
read -u 3 sts line
checkStatus "$sts" "$line" 354
echo "Subject: ${Subject}" >&3
echo "${Message}" >&3
echo "." >&3
read -u 3 sts line
checkStatus "$sts" "$line"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)