2

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?

3
  • 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, 2013 at 15:38
  • 1
    But IMHO you are describing the reasons why many sysadmin decided to switch from sendmail to postfix :)
    – user130370
    Jan 8, 2013 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, 2013 at 15:43

4 Answers 4

2

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

1
  • 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[157.56.242.230]:587: Connection timed out
    – Rhyuk
    Jan 9, 2013 at 14:00
2

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?

6
  • 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[157.56.242.230]:587: Connection timed out
    – Rhyuk
    Jan 9, 2013 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, 2013 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 -- 0.0.0.0/0 0.0.0.0/0 state NEW tcp dpt:587
    – Rhyuk
    Jan 10, 2013 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, 2013 at 16:11
  • 1
    After all it was that my companys network was blocking SMTP.
    – Rhyuk
    May 13, 2013 at 20:05
1

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

1

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
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
1
  • I didnt test it but you have done very good work!
    – drmaa
    Aug 18, 2019 at 16:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .