Google Plus

Configuring Sendmail SMTP server on CentOS & Scientific Linux

Written by Mel Kham on . Posted in CentOS

Sendmail is the default SMTP (Simple mail transfer protocol) server installed on CentOS and although it can be slightly more complicated for beginners to learn than similar alternatives such as Postfix, it can be quite powerful and useful to learn. Sendmail by itself as the name suggests is a MTA (Mail transfer agent) which is useful for sending emails from your server to other servers. However in order to create a proper mail server you will also need a few other pieces of

software such as a MUA (Mail user agent) to connect to the MTA and a POP3/IMAP (Post office protocol / Internet message access protocol) server to listen for incoming emails. These will all be covered in later tutorials, but in this tutorial we will just cover some of the basics of Sendmail to help you become familiar with email servers.

1- Terms

This all might be a bit confusing to understand at first, but it’s actually quite straight forward once you get to know all of the terms. I have included some more information below which will help you to remember some of the terms and their role in a mail server.

MTA – Mail Transfer Agent – Sendmail, Postfix

MDA – Mail Delivery Agent – Procmail

MUA – Mail User Agent – Outlook, Thunderbird

SMTP – Simple Mail Transfer Protocol – Sendmail, Postfix

POP3 – Post Office Protocol 3 – Dovecot

IMAP – Internet Message Access Protocol – Dovecot

senmail

 

Sendmail can also be used exclusively for the use of scripts and programs that do not require an email back. One example of this is PHP, many web applications require Sendmail to be installed in order to send out Administrator emails containing password information.

I will begin by presuming that you have a domain name and that you know how to modify the DNS records for your domain name.

To check what version of Sendmail is installed you can enter the following command

 rpm –qa sendmail

 If you are not using the latest version of Sendmail you can update Sendmail by using yum

 yum update sendmail

 Next you should make sure that the sendmail service is running and that it loads on startup

 service sendmail restart

chkconfig sendmail on

 

Next we will need to open up and modify the Sendmail config file located in /etc/mail/sendmail.mc and remove the line which limits Sendmail to work only from the local IP.

 DAEMON_OPTIONS(`Port=smtp, Addr=127.0.0.1 Name=MTA’)dnl

to

DAEMON_OPTIONS(`Port=smtp, Name=MTA’)dnl

 Once you have saved the configurations restart Sendmail again.

service sendmail restart

 You will also need to make sure that if you are using a firewall that you allow incoming and outgoing connections to port 25.

 

2-DNS Records

 Next you will need to modify your DNS records so that you can use your domain name as an email address. First you will need to create a sub-domain under your domain name, for example mail.example.com then you will need to forward the MX records of mail.example.com to point to the IP address of your server. Modifying the records of your DNS server particularly if you are using an external hosting company may take 24 to 48 hours to propagate, so make sure that your settings are correct before you modify them.

3- Accepting incoming mail

You will also need to specify on your server which domains you would like to accept mail from. You can do this by editing the /etc/mail/local-host-names file and adding the domain names as well as the sub-domains that you wish to accept.

 For example you can add the following lines to the file.

 example.com

mail.example.com

 

4- Testing Sendmail

 Finally you can test out if Sendmail is working by either using the mail command or Sendmail itself. Sending emails from mail is much easier as it formats the email for you, but Sendmail will allow you to pipe a file into the email.

 mail example@gmail.com

 cat email.txt | sendmail example@gmail.com

 

5- Using your domain name

 When you check your email the first thing you will notice is that your email came from your hostname not your domain name. If you want a quick fix to change this you can simply change your hostname to become your domain name either through the /etc/hosts file or by entering the following command.

 hostname example.com

 You can also masquerade as another domain name through the sendmail.mc file. Adding the following lines to your sendmail.mc file will allow all your emails to appear as though they are coming from the domain name example.com.

 

MASQUERADE_AS(`example.com’)dnl

MASQUERADE_DOMAIN(localhost)dnl

FEATURE(masquerade_entire_domain)dnl

 

6- Forwarding emails

Sendmail also has the ability to forward emails to multiple addresses; you can do this by editing the alias file located at /etc/aliases. The aliases file allows you to forward emails to local accounts or other emails. This is especially useful for people who want to create a simple mailing list or create email groups.

 For example if you have a set of users to answer support emails you could add the following line to /etc/aliases to allow them all to receive supports emails.

 support: bob, henry, john, support@example.com

 

7- Setting relay access

 By default only the localhost is setup to be able to relay emails to other servers. You can give relay access to users by specifying the servers you’d like them to connect to or the IP that they are connecting from.

 To modify the relay access open the /etc/mail/access file

 You can relay or reject domain names by adding the lines below

 To:gmail.com RELAY

To:spam.com REJECT

 You can also specify IP addresses of hosts you would like to relay or reject

 Connect:127.0.0.1 RELAY

Connect:123.123.123.123 REJECT

That is all.

{module user9-footer}

For questions please refer to our Q/A forum at : http://ask.unixmen.com

Mel Kham

Founder of Unixmen, Living in Amsterdam. Am working in my free time to help people to understand the Opensource and to explain them in easy way how to make the fist steps to the the light. Working day and night with my Co-founder Zinovsky to keep this website live even with less resources.
  • http://www.itchimes.com/ Web Development Company

    Very nice post! It is just what i am looking for. Thank you for sharing informative blog.

  • mickey

    great post. Thank you very much!

  • Vishweshwar Joshi

    I want to send and receive mails from my centos6 system to my office’s mail srever When i configured Thunderbird it works fine but in bugzilla I am not sending and receiving mails

  • Pingback: Cant get php mail() to send email

Like us on Facebook

This week Top Posts

Write for us

Recent Comments

Ladi Oyekanmi

|

Could you please assist in step by step on how to install nagios on solaris

Adhraa

|

Greate tutorial :)

pigmej

|

Just one thing:

What about pep8 in your python code ? How can you give ‘tutorials’ on quite popular website, of such a bad quality ?

Amit Rai

|

I just renamed shared.xml and it logged in and created a new shared.xml.

DB Griffin

|

Larry Page is not being completely honest! The manner in which the PRISM program/project works does not need access from company administrators or owners, so called “direct access”; the access to the information is already there. These tech company CEOs take for granted the actual intelligence of most end users of their products. All it takes is a little digging and reading to go from ignorant to informed on these things especially on exactly how the internet works/functions in the U.S.A. I find Larry Page’s remarks just as laughable as Al Gore’s claim to “inventing” the internet/world wide web!

If you, as an end user, are reading this post; I challenge you to research these matters yourself. It really is quite simple with all the “information sites” that exist on the web today ie Wikipedia, & other online encyclopedias that actually list source material, as well as highly respected tech sites and blogs that also list their source material. Be warned: this is only the tip of the iceberg and these tech CEOs know and understand this; they are scrambling in attempt to perform DAMAGE CONTROL to save the company and what little trust thay have left from their products end users/consumers.

Am I a skeptic? I believe someone has to be or needs to be at this point in time! If your not just a little skeptical of the government, tech companies, and the people that are in charge of these agencies and companies; you need to be, even if just a little skeptic. For your own personal protection and security! I know I was a part of this community for over 14 years!

 
IDG Tech Network
Copyright © 2008-2013 Unixmen.com .
Maintained by Anblik .