How to use sendmail to configure SMTP server
[Environment]
OS : Redhat Fedora 2
sendmail : 8.12.11
[Configure sendmail]
sendmail server will be run according to sendmail.cf that is a sealed book, so we had better not edit it. sendmail.mc use m4 tool to generate sendmail.cf, the best way is to open this file and modify it. Sendmail.mc has very good commentary to explain each entry function. With the help of it, if you can not understand it correctly, please visit http://www.sendmail.org/ which will provide FAQs and tutorials. This article focuses on how to modify it to build SMTP service, so here, I will not explain them in detailJ.
Sendmail.mc is located at /etc/mail directory in my linux server. The following steps will try my best to make it clear for readers.
1) Open sendmail.mc
#cd /etc/mail
#vim sendmail.mc
2) Add two ports to detect connecting request. The following causes sendmail to additionally listen to port 587 for mail from MUAs that authenticate. Roaming users who can't reach their preferred sendmail daemon due to port 25 being blocked or redirected find this useful. If relative ports have been commented, please remove commentary.
DAEMON_OPTIONS(`Port=25, Name=MTA')dnl
DAEMON_OPTIONS(`Port=587, Name=MSA, M=Ea')dnl
3) Comment two entries. The first entry will only listen on the IPv4 loopback address 127.0.0.1 and not on any other network devices. Remove the loopback address restriction to accept email from the internet or intranet. The second entry permit unresolvable domains to send spam(garbarge emails). We had better disable the two functions, right?!
DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA’)dnl
FEATURE(`accept_unresolvable_domains’)dnl
4) Add or uncomment four entries for authenticatation. The fisrt and second entries provide authenticating method, and PLAIN is the preferred plaintext authentication method. The third denotes where the user information database for authentication. The last one is used to sent emails out through an external mail server.
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/client-info.db')dnl
define(`SMART_HOST',`smtp.sina.com')
5) Clear all old dababases, and rebuild them again. Makefile should invoke m4 tool to convert sendmail.mc to sendmail.cf.
#cd /etc/mail
#make clean
#make
6) Restart sendmail server. If other email servers are running, please stop them firstly.
#service sendmail restart
[TIPS]
How to get current version of sendmail?
There are two ways to get current version of sendmail. Please follow following commands, they are executed in my linux server.
1) Use telnet to get version. Please use ‘ctrl+]’ and ‘quit’ command to quit telnet command. ‘bugzilla’ is the domain name of linux server.
#telnet bugzilla 25
Trying 127.0.0.1...
Connected to BugzillaTestServer (127.0.0.1).
Escape character is '^]'.
220 bugzilla.utl.com ESMTP Sendmail 8.12.11/8.12.11; Thu, 6 Apr 2006 13:49:13 +0800
^]
telnet> quit
Connection closed.
2) Use sendmail’s debugging options to show current version.
# sendmail -d0.1
Version 8.12.11
Compiled with: DNSMAP HESIOD HES_GETMAILHOST LDAPMAP LOG MAP_REGEX
MATCHGECOS MILTER MIME7TO8 MIME8TO7 NAMED_BIND NETINET NETINET6
NETUNIX NEWDB NIS PIPELINING SASLv2 SCANF STARTTLS TCPWRAPPERS
USERDB USE_LDAP_INIT
============ SYSTEM IDENTITY (after readcf) ============
(short domain name) $w = bugzilla
(canonical domain name) $j = bugzilla.utl.com
(subdomain name) $m = utl.com
(node name) $k = BugzillaTestServer
========================================================
Recipient names must be specified
How to build client-info database?
1) Create client-info file at the /etc/mail, and input contents:
AuthInfo:your.isp.net "U:root" "I:user" "P:password".
For example,
AuthInfo:stmp.sina.com “U:root” “I:hello_wyq” “P:no_ways”.
After editing it, please save and close it. Of course,
you can create this file in any directory, and
use ‘ln –s your_directory/client-info /etc/mail/client-info’ to link it.
Please remember that the access right must be root for safety!
2) Generate client-info.db file. There are two ways to create it.
I) Use ‘makemap’ command directly
#cd /etc/mail
#chmod 600 client-info
#makemap hash client-info < client-info
#chmod 600 client-info.*
#m4 sendmail.mc > sendmail.cf
II) Use Makefile, and add client-info.db in the ‘all:’ tag.
Makefile will automatically generate sendmail.cf in the
light of sendmail.mc.
#cd /etc/mail
#chmod 600 client-info
#make clean
#make
How to confirm whether SASL has been initialized?
# sendmail -d0.1 -bv root | grep SASL
NETUNIX NEWDB NIS PIPELINING SASLv2 SCANF STARTTLS CPWRAPPERS
If there are some words like above, it means that SASL has been initialized. SASL is essential element for authentication.
How to check whether PLAIN has been initialized?
[root@BugzillaTestServer mail]# telnet bugzilla 25
Trying 127.0.0.1...
Connected to bugzilla.utl.com (127.0.0.1).
Escape character is '^]'.
220 bugzilla.utl.com ESMTP Sendmail 8.12.11/8.12.11; Thu, 6 Apr 2006 15:15:42 +0800
EHLO bugzilla
250-bugzilla.utl.com Hello BugzillaTestServer [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN
250-DELIVERBY
250 HELP
^]
telnet> quit
Connection closed.
If PLAIN is shown, it means that the configuration is OK.
How to test whether we can send emails by SMTP server?
# echo 'Test body of email and no titile' | sendmail -v hello_wyq@sina.com
hello_wyq@sina.com... Connecting to [127.0.0.1] via relay...
220 bugzilla.utl.com ESMTP Sendmail 8.12.11/8.12.11; Thu, 6 Apr 2006 15:20:52 +0800
>>> EHLO bugzilla.utl.com
250-bugzilla.utl.com Hello BugzillaTestServer [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN
250-DELIVERBY
250 HELP
>>> MAIL From:<root@bugzilla.utl.com> SIZE=33 AUTH=root@bugzilla.utl.com
250 2.1.0 <root@bugzilla.utl.com>... Sender ok
>>> RCPT To:<hello_wyq@sina.com>
>>> DATA
250 2.1.5 <hello_wyq@sina.com>... Recipient ok
354 Enter mail, end with "." on a line by itself
>>> .
250 2.0.0 k367Kq5j006558 Message accepted for delivery
hello_wyq@sina.com... Sent (k367Kq5j006558 Message accepted for delivery)
Closing connection to [127.0.0.1]
>>> QUIT
221 2.0.0 bugzilla.utl.com closing connection
Please check your email inbox whether no subject’s email has been received, good Luck!