我在谷歌云中运行的是CentOS 7虚拟机,但在使用sendmail发送电子邮件时遇到了困难。我关注了下面的帖子和其他许多帖子,但结果仍然是一样的,即邮件永远不会到达目的地。
https://linuxconfig.org/configuring-gmail-as-sendmail-email-relay
https://www.bonusbits.com/wiki/HowTo:Configure_SendMail_to_Use_SMTP_Relay
https://tecadmin.net/sendmail-to-relay-emails-through-gmail-stmp/
http://ibgwww.colorado.edu/~lessem/psyc5112/usail/mail/debugging/
我使用telnet会话从服务器连接到smtp-relay.gmail.com进行测试,并且能够连接并发送邮件,邮件也到达了目的地。
请原谅我的无知,我对Linux非常陌生。当我使用邮件-v命令发送邮件时,我得到了下面的输出。
[root@backend-main-test mail]# echo "Just testing gmail relay" | mail -v -s "Sendmail gmail relay" myemailaddress@somewhere.com
myemailaddress@somewhere.com... Connecting to [127.0.0.1] via relay...
220 backend-main-test.c.somecompany.internal ESMTP Sendmail 8.14.7/8.14.7; Sun, 3 Jun 2018 17:59:57 GMT
>>> EHLO backend-main-test.c.somecompany.internal
250-backend-main-test.c.somecompany.internal Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-DELIVERBY
250 HELP
>>> MAIL From:<root@backend-main-test.c.somecompany.internal> SIZE=252
250 2.1.0 <root@backend-main-test.c.somecompany.internal>... Sender ok
>>> RCPT To:<rualdventer@gmail.com>
>>> DATA
250 2.1.5 <myemailaddress@somewhere.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 w53Hxvqg002267 Message accepted for delivery
myemailaddress@somewhere.com... Sent (w53Hxvqg002267 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 backend-main-test.c.silveraxiom-prod.internal closing connection
[root@backend-main-test mail]#
它在最后给出了消息"Message accepted for delivery“,但在开始时它说正在连接到127.0.0.1 (本地主机),它不应该连接到我在sendmail.mc和auth / authinfo文件配置中指定的smtp-relay.gmail.com主机吗?
根据/var/log/maillog,当我执行这些命令时,它会给出类似于上面的"Message accepted for delivery“,并且中继被指定为127.0.0.1
发布于 2019-02-21 04:29:15
我为ubuntu和centos创建了一个sendmail via Gmail脚本。如果你喜欢,你可以自由地使用它。
#! /bin/bash
date=$(date +"%Y-%m-%d")
logFile=:Log File Location Goes HERE
authInfoPath="/etc/mail/authinfo/"
idpass="/etc/mail/authinfo/gmail-idpass"
sendmail="/etc/mail/sendmail.mc"
## Functions
determineLinuxFlavor()
{
os=$(grep -i "NAME=\"Amazon\ Linux\ AMI\"" /etc/os-release)
if [ -z "$os" ]; then
os=$(grep -i "NAME=\"Ubuntu\"" /etc/os-release)
if [ -z "$os" ]; then
os="UNKNOWN"
else
os="UBUNTU"
fi
else
os="CENTOS"
fi
printf $os
}
os=$(determineLinuxFlavor)
## About to start configuring send mail to relay through Gmail. ##
## @TODO: get the OS version and install dependencies based on OS
if [ $# -eq 5 ]; then
email=$1
password=$2
response=$3
choice=$4
personal=$5
else
# ask questions here
echo "## Enter the credentials of Gmail User account you wish to use. ##"
read -r -p "Enter the username of the Gmail account you are adding: " email
read -r -p "Enter the password of the Gmail account you are adding: " password
read -r -p "Would you like to send a test email? [y/N] " response
read -e -p "Would you like to check the log tail for errors? [y/n] " choice
read -e -p "Enter a personal email address to test the relay instalation: " personal
fi
## About to install the requiring dependencies... ##
if [ "$os" == "UBUNTU" ]; then
## Upgrading Ubuntu to the latest Sendmail Version. ##
apt-get install -y sendmail mailutils sasl2-bin > /dev/null 2>&1
elif [ "$os" == "CENTOS" ]; then
## Upgrading CentOS to the latest Sendmail Version. ##
yum -y install sendmail mailutils mailx sendmail-bin sendmail-cf cyrus-sasl-plain
else
Invalid Flavor of Linux
exit
fi
echo -e ' \t '
## Create Gmail authentication file in a folder in which you will add Gmail user name and password.
echo -e ' \t '
mkdir $authInfoPath
cd $authInfoPath
echo "AuthInfo: \"U:root\" \"I:$email\" \"P:$password\"" >> $idpass
makemap hash $idpass < $idpass
chmod 700 $authInfoPath
echo -e ' \t '
echo -e ' \t '
echo "## Gmail Authentication Info injection complete. ##"
echo "Backing up Sendmail config File."
cp $sendmail $sendmail.$date
echo "Injecting Gmail Relay Code into sendmail.mc file."
cat <<'eof' >/tmp/gmail.conf
# Adding config for gmail #
define(`SMART_HOST', `[smtp.gmail.com]')dnl
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl
define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
define(`confAUTH_OPTIONS', `A p')dnl
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
FEATURE(`authinfo',`hash -o /etc/mail/authinfo/gmail-idpass.db')dnl
# End config for gmail #
eof
if [ "$os" == "UBUNTU" ]; then
sed -i $'/MAILER_DEFINITIONS/{e cat /tmp/gmail.conf\n}' $sendmail
elif [ "$os" == "CENTOS" ]; then
sed -i '/dnl MASQUERADE_DOMAIN(mydomain.lan)dnl/r /tmp/gmail.conf' $sendmail
fi
echo -e ' \t '
echo "## Injection of Gmail Relay Code into Sendmail.mc Complete. ##"
echo "Rebuilding Sendmail & Restarting Service."
make -C /etc/mail
/etc/init.d/sendmail restart
if [ "$os" == "UBUNTU" ]; then
mail="mail.log"
elif [ "$os" == "CENTOS" ]; then
mail="maillog"
fi
case "$response" in
[yY][eE][sS]|[yY])
echo -e "Mail Body - Test Message" | mail -s "TMBC is Mail Sending from CLI" -r $email $personal
[[ "$choice" == [Yy]* ]] && tail -n 10 /var/log/$mail || echo "Skipping log tail!"
;;
*)
echo "Skipping send test!"
;;
esac
https://stackoverflow.com/questions/50669700
复制相似问题