Tuesday, October 2, 2012

Send email from command line through an MS Exchange Relay (Alt title: Installing SSMTP on CentOS 5.x)

The situation required me to use an existing MS Exchange Server as a mail relay to send an email from a custom notification shell script I'm working on.

I tried configuring Postfix, Sendmail, Mailx, Nail, all to no avail. This took quite some time in troubleshooting and Google was not particularly helpful.

Eventually I stumbled across this post, which mentioned using the EPEL repo's to install SSMTP. Simple, but effective.

Therefore, this entry focuses on how to setup your server to relay mail, using the SSMTP package (because it works)


0. Login as root or su.

1. Check to ensure that the permissions are correct to relay mail.
telnet my.emailserver.ip.address 25
EHLO
MAIL FROM: myvalidsenderaddress@foobar.org
RCPT TO: myvalidrecipient@foobar.org
DATA
This is a test message.
. <Hit Enter>


quit

You should have received an email if the permissions are correct.

2. Install the EPEL repo

cd /tmp
wget http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-4.noarch.rpm

 Please use this alternative if the original does not work. - http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm

rpm -Uvh epel-release-5-4.noarch.rpm

3. Remove sendmail
yum remove sendmail

4. Install SSMTP
yum install ssmtp --enablerepo=EPEL

5. Configuration
Backup original conf file
cp /etc/ssmtp/ssmtp.conf /etc/ssmtp/ssmtp.conf.bkp

Edit the conf file
nano /etc/ssmtp/ssmtp.conf 

Edit the following lines:
mailhub=my.emailserver.ip.address:25
Hostname=ValidDomainHostName.foobar.org

*Depending on your configuration, you may or may not need TLS, check the SSMTP.conf man for details.

6. Restart service
service ssmtp restart

7. Test the application
echo "This is the body of my email" | ssmtp myemail@foobar.org

That's it!

This worked for me where all the others mysteriously failed. Now I'm off to finish my script. I'll post another update soon!

-noveck

15 comments:

  1. This was wonderful. the MS Exchange Relay is awesome service. Interesting Forwards

    ReplyDelete
  2. Self-assertive and amazing in equal measures, a must read.
    DuoCircle - Anti-Phishing

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. I got too much interesting stuff on your blog. I guess I am not the only one having all the enjoyment here! Keep up the good work. learn more about Hotmail

    ReplyDelete
  5. Hey, very nice site. I came across this on Google, and I am stoked that I did. I will definitely be coming back here more often. Wish I could add to the conversation and bring a bit more to the table, but am just taking in as much info as I can at the moment. Thanks .

    DedicatedHosting4u.com

    ReplyDelete
  6. Great. It is good to constantly coming up with creative ideas. Provides much needed knowledge. goal oriented blog posts and always tried to find creative ways to meet goals.

    Thanks
    Online affiliates

    ReplyDelete
  7. thanks for the tips and information..i really appreciate it..
    ceo email

    ReplyDelete
  8. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic. If possible, as you gain expertise, would you mind updating your blog with more information? It is extremely helpful for me. find social media links

    ReplyDelete
  9. Thankyou so much for this. I'm really a big fan of linux. Windows is just uselesss.. I'm using UBUNTU right now.

    ReplyDelete
  10. thank you for this such a good information about hotmail email login on www.hotmail.com

    ReplyDelete
  11. Oh that's really great... thankyou so much for sharing.. Works really perfect for me.. hotmail login

    ReplyDelete
  12. Thanks for taking the time to discuss this, I feel strongly about it and love learning more on this topic.
    hotmail

    ReplyDelete
  13. We have sell some products of different custom boxes.it is very useful and very low price please visits this site thanks and please share this post with your friends. como abrir correo hotmail

    ReplyDelete
  14. that's awesome.. thankyou so much .. i've been looking for it.. really helpful.. gmail sign in

    ReplyDelete

  15. Thanks for the post it’s really informative.

    google photos login

    ReplyDelete