I have a box running RHEL 6.3 and there's and application that needs to send out reports by mail, in order for this functionality to work I have to have mail configured in my box. In addition I thought it would be nice to receive my root alerts to my regular email instead of having to log into the box.

I have an Office 365 account created for the sole purpose of being used as the relay.

Office 365 SMTP Details:

SMTP: pod51011.outlook.com Port:587 Encryption: TLS

What I tried:

- 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.

After 8 hours of multiple tries:

- 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.

And here I am, seeking for assistance cause I want to beat sendmail! Can anyone point me in the right direction?

  • IIRC I had something similar to this working in production : cyberciti.biz/faq/… I don't know if it works for encrypted smtp
    – user130370
    Jan 8 '13 at 15:38
  • 1
    But IMHO you are describing the reasons why many sysadmin decided to switch from sendmail to postfix :)
    – user130370
    Jan 8 '13 at 15:39
  • I saw that guide, but it makes changes directly to sendmail.cf (which in the header of it clearly says its a no-no) and it doesn't incorporate authentication with TLS. Meanwhile I'll research about postfix. Thanks!
    – Rhyuk
    Jan 8 '13 at 15:43

I also tried doing this with sendmail relaying via gmail, but opted to use postfix instead as it seemed MUCH more simple to setup. You dont have to go through the process of creating self signed certificates etc.. This howto is for gmail, but the process should be very similar for Office 365. Just a matter of finding out the server names, and authentication scheme. http://rs20.mine.nu/w/2011/07/gmail-as-relay-host-in-postfix/ Geo

  • I followed the tutorial and this is what I'm getting: Jan 9 09:52:47 isvahlrtk01 postfix/smtp[12065]: connect to pod51011.outlook.com[]:587: Connection timed out
    – Rhyuk
    Jan 9 '13 at 14:00

After changing sendmail.mc did you run /etc/mail/make in order to build sendmail.cf? Did you also run service sendmail restart after generating the new sendmail.cf?

  • Yes sir, did all that. I think it's gotta be network related, even though I have port 25/587 opened in my firewall. And right now (and the closest Ive been) is trying with postfix and I get this Jan 9 09:52:47 isvahlrtk01 postfix/smtp[12065]: connect to pod51011.outlook.com[]:587: Connection timed out
    – Rhyuk
    Jan 9 '13 at 20:35
  • 2
    The log message that you provide shows that the machine is longer running sendmail but postfix. Second the same log message shows that something is blocking port 587 traffic from that machine to pod51011.outlook.com
    – adamo
    Jan 10 '13 at 9:23
  • I created rules in my firewall for the input/output chain (just in case) for port 587. iptables -L -n command shows me ACCEPT tcp -- state NEW tcp dpt:587
    – Rhyuk
    Jan 10 '13 at 14:44
  • 1
    But can you telnet pod51011.outlook.com 587 ? If not, some router along the way (or pod51011.outlook.com) is blocking access.
    – adamo
    Jan 10 '13 at 16:11
  • 1
    After all it was that my companys network was blocking SMTP.
    – Rhyuk
    May 13 '13 at 20:05

The reason why I couldn't connect to the SMTP was because my company was blocking SMTP access. Ended up using a local SMTP and used Postfix with these instructions to make it work.

Postfix relay through another mailserver


I created a script to add gmail account to sendmail if anyone is interested.

#! /bin/bash

date=$(date +"%Y-%m-%d")
logFile=:Log File Location Goes HERE

## Functions

    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 

    printf $os


## 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
    # 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

## 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
    Invalid Flavor of Linux
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
FEATURE(`authinfo',`hash -o /etc/mail/authinfo/gmail-idpass.db')dnl
# End config for gmail #

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

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
elif [ "$os" == "CENTOS" ]; then

case "$response" in
        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!"
  • I didnt test it but you have done very good work! Aug 18 '19 at 16:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.