Detailed configuration of sendmail+openwebmail under LNMP environment

Source: Internet
Author: User
Tags imap dovecot install perl

 

With the development and popularization of network, mail server is becoming an indispensable part of people's daily life. Today, many enterprises use Lotus Note, Exchange as a mail server inside the company. This paper mainly introduces a kind of mail server Software (sendmail) based on Linux system toprovide mail service.

Note: The LNMP Web environment was previously configured.

Configuration process/steps:

1. Installing SendMail
Yum installation or RPM package installation:
Yum-y install SendMail sendmail-devel SENDMAIL-CF sendmail-do M4

2. Set up at System 3 and level 5
Chkconfig--level SendMail on
Chkconfig--list SendMail
SendMail 0: Off 1: Off 2: Enable 3: Enable 4: Enable 5: Enable 6: Off

3. Add mail service domain name for mail server
vim/etc/mail/local-host-names
Add: "Linux.com" to the Local-host-names file

4. Turn on the SendMail server's network interface
CP SENDMAIL.MC Sendmail.mc.bak to prevent errors, backup the configuration file
Vim/etc/mail/sendmail.mc
Find: Daemon_options (' port=smtp,addr=127.0.0.1, Name=mta ') dnl
Modified to: Daemon_options (' port=smtp,addr=0.0.0.0, Name=mta ') dnl

5. Set up user authentication for SMTP
Vim/etc/mail/sendmail.mc
Find:

Login PLAIN ') dnldnl define (' confauth_mechanisms ', ' EXTERNAL GSSAPI digest-md5 cram-md5 LOGIN PLAIN ') dnl

Remove the previous comment: "DNL"

The SASLAUTHD service program is used in the SendMail server to provide the user authentication function, so to open it
Chkconfig--level SASLAUTHD on
Service SASLAUTHD Start

6. Generate the Sendmail.cf file
Cd/etc/mail
M4 SENDMAIL.MC > SENDMAIL.CF
Service SendMail Restart

7. User Management
Groupadd mailuser/* Set up a mail user group */
Useradd-g mailuser-s/sbin/nologin Mike/* Create a mail user who cannot log on to the system */
Vim/etc/aliases/*sendmail uses the aliases mechanism to implement mail aliases and bulk functions * *
Admin:mike/*admin is Mike's nickname.
Testgroup:mike,john,tom,jack/* Mail mass, send to Testgroup mailbox is sent to 4 people * *
newaliases/* Update to ALIASES.DB database */

8. Installing the POP3,IMAP function
Yum Install Dovecot
Vim/etc/dovecot.conf
Find: protocols = IMAP IMAPS
Modified to: protocols = IMAP IMAPS POP3 pop3s
Chkconfig--level Dovecot on
Service Dovecot Restart

Here SendMail has been configured to complete, after you turn on the server, you can use the Outlook mail client software to send and receive mail. The following is an introduction to the installation of Openwebmail:

9. Installing Openwebmail
Download the required packages: www.openwebmail.org www.rpmfind.net
Yum install perl-cgi-speedycgi perl-suidperl perl-compress-zlib perl-text-iconv
RPM–IVH--nodeps openwebmail-data-2.53-3.i386.rpm
RPM–IVH--nodeps openwebmail-2.53-3.i386.rpm

10. Initializing the Openwebmail system
/var/www/cgi-bin/openwebmail/openwebmail-tool.pl--init

11. Modify the configuration file
Vim/var/www/cgi-bin/openwebmail/etc/openwebmail.conf
Domainnames linux.com
Default_language ZH_CN. GB2312
Default_iconset Cool3D.Chinese.Simplified

12. Installing Perl's fastcgi module
Download fcgi:http://cpan.wenzk.com/authors/id/f/fl/flora/fcgi-0.71. tar.gz
Tar zxvf fcgi-0.71.tar.gz
CD FCGI-0.71
Perl makefile.pl
Make && make install
RPM-IVH perl-fcgi-procmanager-0.18-1.el4.rf.noarch.rpm
Or: Yum install Perl-fcgi-procmanager

13. Configuring Perl's fastcgi script (perl-fast)

Vim/etc/init.d/perl-fast

#!/usr/bin/perl-Wuse fcgi;use socket;use FCGI::P rocmanager;subShutdown {fcgi::closesocket ($socket);Exit }sub Restart {fcgi::closesocket ($socket); &main;} Use Sigtrap ' handler ', \&shutdown, ' normal-signals '; use sigtrap ' handler ', \&restart, ' HUP '; require ' syscall.ph '; use POSIX qw (SETSID);Export fcgi_socket_path= "/tmp/perl-fastcgi.sock" #export fcgi_nprocesses=4#&daemonize; We don ' t daemonize when running under Runsv#this keeps the program alive or something afterexec ' ing perl scriptsend () {}begin () {}{no Warnings;*core::global::exit = sub {die "fakeexit\nrc=". Shift (). "\ n"; };}; Eval q{exit};if ([email protected]) {exit unless [email protected] =~/^fakeexit/;} &main;sub daemonize () {chdir '/' or die ' Can ' t chdir to/: $! "; Defined (my $pid = fork) or die "Can ' t fork: $!"; Exit if $pid; Setsid () or die "Can ' t start a new session: $!";Umask 0;} Sub Main {# ....IP sockets# $socket = fcgi::opensocket ("127.0.0.1:8999", 10); UNIX sockets# $socket = Fcgi::opensocket ("/temp/perl-fastcgi.sock"), #foreach $item (keys%ENV) {delete $ENV {$item};} #.. fastcgi........my $n _processes = $ENV {fcgi_nprocesses} | | 4; $proc _manager = FCGI::P rocmanager->new ({n_processes = $n _processes}); Unix Socket$socket = Fcgi::opensocket ("$ENV {Fcgi_socket_path}", 10); Socket:chmod 0777, $ENV {fcgi_socket_path};; #use UNIX Sockets-user Running this script must has W access to the 'Nginx ' folder!! $request =fcgi::request (\*stdin, \*stdout, \*stderr, \%req_params, $socket, &fcgi::fail_accept_on_intr); $proc _ Manager->pm_manage (); if ($request) {request_loop ()}fcgi::closesocket ($socket);} Sub Request_loop {while ($requestAccept () >= 0) {$proc _manager->pm_pre_dispatch (); #processing any STDIN input from WebServer (for cgi-post actions) $ Stdin_passthrough = "; {no warnings; $req _len = 0 + $req _params{' content_length '};}; if (($req _params{' request_method '} eq ' POST ') && ($req _len! = 0)) {my $bytes _read = 0;while ($bytes _read &lt ; $req _len) {My $data = "; My $bytes =Read (STDIN, $data, ($req _len-$bytes _read));Last if ($bytes = = 0 | |!defined ($bytes)); $stdin _passthrough. = $data; $bytes _read + = $bytes;}} #running the CGI appif (-x $req _params{script_filename}) && #can I execute this? (-S $req _params{script_filenam E}) && #Is thisFile empty? (-R $req _params{script_filename}) #can I read this file?) {Pipe (CHILD_RD, PARENT_WR);p ipe (Parent_err, child_err); my $pid = open (Child_o, "-|"); Unless (defined ($pid)) {print ("content-type:text/plain\r\n\r\n ");p rint" error:cgi app returned no output-executing $req _params{script_filename} failed!\n "n ext;} $OLDFH = select (Parent_err); $| = 1;select (child_o); $| = 1;select ($OLDFH), if ($pid > 0) {Close (CHILD_RD), close (child_err);p rint parent_wr $stdin _passthrough;close (PARENT _WR); $rin = $rout = $ein = $eout = "; Vec ($rin, Fileno (Child_o), 1) = 1;vec ($rin, Fileno (Parent_err), 1) = 1; $ein = $r In; $nfound = 0;while ($nfound =select ($rout = $rin, undef, $ein = $eout, ten)) {die "$!" unless $nfound! =-1; $r 1 = VEC ( $rout, Fileno (Parent_err), 1) = = 1; $r 2 = Vec ($rout, Fileno (Child_o), 1) = = 1; $e 1 = VEC ($eout, Fileno (Parent_err), 1) = = 1; $e 2 = Vec ($eout, Fileno (Child_o), 1) = = 1;if ($r 1) {while ($bytes = Read (Parent_err, $errbytes, 4096)) {print STDERR $errbytes;} if ($!) {$err = $!; Die $!; VEC ($rin, Fileno (Parent_err), 1) = 0unless ($err = = EINTR or $err = = Eagain);}} if ($r 2) {while ($bytes = Read (Child_o, $s, 4096)) {print $s;} if (!defined ($bytes) {$err = $!; Die $!; VEC ($rin, Fileno (Child_o), 1) = 0unless ($err = = EINTR or $err = = Eagain);}} Last if ($e 1 | | $e 2);} Close Child_rd;close parent_err;waitpid ($pid, 0);} else {foreach $key (keys%req_params) {$ENV {$key} = $req _params{$key};} # CD to the script ' s local directoryif ($req _params{script_filename} =~/^ (. *) \/[^\/]+$/) {chdir $;} Close (PARENT_WR); #close (Parent_err); close (STDIN); close (STDERR); #fcntl (Child_rd, F_DUPFD, 0); Syscall (&sys_ Dup2, Fileno (CHILD_RD), 0); Syscall (&sys_dup2, Fileno (Child_err), 2); #open (STDIN, "<&child_rd"); Exec ($req _params{script_filename});d ie ("exec failed");}} else {print ("content-type:text/plain\r\n\r\n");p rint "Error:no such CGI app-$req _params{script_filename} may not exist Or is not executable by this process.\n ";}}}

chmod +x/etc/init.d/perl-fast
Vim/etc/profile

Add the following content:

Export fcgi_socket_path= "/tmp/perl-fastcgi.sock" Export fcgi_nprocesses=4

Executes the Perl-fast script, which runs in the background.
Source/etc/profile
/etc/init.d/perl-fast &

14. Configure the enable_perl.conf file and put the file in the nginx/conf directory. The contents are as follows:

#Enable Openwebmailfastcgi_pass Unix:/tmp/perl-fastcgi.sock;fastcgi_index Openwebmail.pl;fastcgi_param GATEWAY _interface cgi/1.1;fastcgi_param server_software nginx;fastcgi_param script_filename $document _root$fastcgi_script_ Name;fastcgi_param query_string $query _string;fastcgi_param request_method $request _method;fastcgi_param CONTENT_ TYPE $content _type;fastcgi_param content_length $content _length;fastcgi_param script_name $fastcgi _script_name; Fastcgi_param Request_uri $request _uri;fastcgi_param document_uri $document _uri;fastcgi_param document_root $ Document_root;fastcgi_param server_protocol $server _protocol;fastcgi_param remote_addr $remote _addr;fastcgi_param Remote_port $remote _port;fastcgi_param server_addr $server _addr;fastcgi_param server_port $server _port;fastcgi_ param server_name $server _name;fastcgi_read_timeout;

Then add fastcgi perl support for Nginx

server {       listen;       server_name mail.linuxde.net;       CharSet gb2312;       Access_log/wslogs/linuxde/mail_access.log combined;       Location/{                root/var/www;                Index index.html index.htm Index. PHP;       }       Location ~*. *\.pl$ {                root/var/www;                Include enable_perl.conf;        }}

15. Publishing Openwebmail in the Web server
To make a guide page without having to enter a long address in the browser
Vim/var/www/index. PHP
<script language=javascript>
Location.href= "cgi-bin/openwebmail/openwebmail.pl";
</script>

16. Settings for file permissions
#Chown root.root/var/www/cgi-bin/openwebmail/
#chown root.mail/var/www/cgi-bin/openwebmail/*
#chmod 775/var/www/cgi-bin/openwebmail/openwebmail*.pl
#chown root.mail/var/www/cgi-bin/openwebmail/openwebmail*.pl
#chmod 4555/usr/bin/suidperl
#chmod 775/var/www/cgi-bin/openwebmail/etc/sessions

Configuration completed, testing and how to use I think it should not be more Shao!

Detailed configuration of sendmail+openwebmail under LNMP environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.