Jas*_*son 11 bash postfix-mta smtp
我有postfix + dovecot.我想制作可以使用SMTP的bash脚本.我不想使用sendmail.
可能吗?可能有人有一些代码示例?
dld*_*dnh 17
男孩,当那个手套被抛出时,它总是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"
Run Code Online (Sandbox Code Playgroud)
用gmail测试,它目前有效.
#!/bin/bash
# Use "host -t mx yourispdomain" to find out yourispmailserver
exec 1<>/dev/tcp/yourispmailserver/25
a=$(cat <<"MAILEND"
HELO local.domain.name
MAIL FROM: <me@local.domain.name>
RCPT TO: <you@local.domain.name>
DATA
From: me@local.domain.name
To: you@local.domain.name
Subject: test
send your orders for pizza to the administrator.
.
QUIT
.
MAILEND
)
IFS='
'
declare -a b=($a)
for x in "${b[@]}"
do
echo $x
sleep 1
done
Run Code Online (Sandbox Code Playgroud)
刚刚发现了这个小巧但很棒的实用程序sendemail(不是sendmail)。语法太简单了,无法解释。
例:
SERVER="smtp.company.com"
FROM="sender@company.com"
TO="recepient@company.com"
SUBJ="Some subject"
MESSAGE="Some message"
CHARSET="utf-8"
sendemail -f $FROM -t $TO -u $SUBJ -s $SERVER -m $MESSAGE -v -o message-charset=$CHARSET
Run Code Online (Sandbox Code Playgroud)
可通过帮助或在作者的站点上获得更多信息:http : //caspian.dotconf.net/menu/Software/SendEmail/。