gpt4 book ai didi

bash - 是否可以通过 smtp 通过 bash 脚本发送邮件?

转载 作者:行者123 更新时间:2023-11-29 08:49:43 25 4
gpt4 key购买 nike

我有 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"

关于bash - 是否可以通过 smtp 通过 bash 脚本发送邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9998710/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com