我有一台运行 RHEL 6.3 的机器,其中有一个应用程序需要通过邮件发送报告,为了使此功能正常工作,我必须在机器中配置邮件。此外,我认为将我的根警报发送到我的常规电子邮件中而不是必须登录到机器中会很好。
我有一个 Office 365 帐户,其唯一目的是用作中继。
Office 365 SMTP 详细信息:
SMTP:pod51011.outlook.com 端口:587 加密:TLS
我尝试过的:
- Defined the SMART_HOST in the sendmail.mc
- Generated and configured sendmail certificates
- Created the AuthInfo file with SMTP credentials
- Eliminated from sendmail.mc localhost's loopback
- Got frustrated because even thought I configured everything (using different guides) sendmail kept trying to send them throught localhost.
经过8个小时的多次尝试:
- Gave up on sendmail and slept 12 hours due to a massive headache.
- Decided to use SSMTP (because sendmail was a PITA) and people said SSMTP was easy to configure.
- Configured SSMTP and for some reason SASLAUTH said it couldn't connect to the SMTP.
- Got frustrated again and uninstalled SSMTP.
我在这里寻求帮助,因为我想打败 sendmail!有人能给我指明正确的方向吗?
答案1
我也尝试过通过 gmail 使用 sendmail 中继来执行此操作,但最终选择使用 postfix,因为它似乎设置起来简单得多。您不必经历创建自签名证书等过程。此操作指南适用于 gmail,但该过程对于 Office 365 应该非常相似。只需找出服务器名称和身份验证方案即可。 http://rs20.mine.nu/w/2011/07/gmail-as-relay-host-in-postfix/ 地理
答案2
更改后sendmail.mc
您是否/etc/mail/make
按顺序运行了构建?生成新的后sendmail.cf
您是否也运行了?service sendmail restart
sendmail.cf
答案3
我无法连接到 SMTP 的原因是我的公司阻止了 SMTP 访问。最后我使用了本地 SMTP,并按照这些说明使用 Postfix 使其正常工作。
答案4
如果有人感兴趣的话,我创建了一个脚本来将 gmail 帐户添加到 sendmail。
#! /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