我有postfix +鸽舍。我想制作可以使用SMTP的bash脚本。我不想使用sendmail。

是否可以?可能有人有一些代码示例吗?

最佳答案

小伙子,当那 Handlebars 套被扔掉时,它总是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/

10-11 15:52