是否可以通过smtp通过bash脚本发送邮件? [英] Is it possible to send mails by bash script via smtp?
本文介绍了是否可以通过smtp通过bash脚本发送邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有postfix +鸽舍.我想制作可以使用SMTP的bash脚本.我不想使用sendmail.
I have postfix+dovecot. I want to make bash script which can use SMTP for this. I don't want use sendmail.
有可能吗?可能有人有一些代码示例吗?
Is it possible? May be someone has some examples of code?
推荐答案
男孩,当那只手套被抛出时,它总是bash
直指我! :-)
Boy, when that gauntlet is thrown, it always bash
es me right upside the head! :-)
#!/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"
这篇关于是否可以通过smtp通过bash脚本发送邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文