LNMP环境下SendMail+OpenWebMail的详细配置
随着网络的发展和普及,邮件服务器正在成为人们日常生活中不可缺少的部分。现在,许多企业采用 Lotus Note, Exchange 作为公司内部的邮件服务器。本文主要介绍一种基于Linux系统的邮件服务器软件(sendmail)提供邮件服务。
注意:之前已经配置好了LNMP web环境。
配置过程/步骤:
1. 安装Sendmail
yum安装或者rpm包安装:
yum -y install sendmail sendmail-devel sendmail-cf sendmail-do m4
2. 设置在系统3和5级别启动
chkconfig --level 35 sendmail on
chkconfig --list sendmail
sendmail 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
3. 添加邮件服务器的邮件服务域名
vim /etc/mail/local-host-names
将:“linux.com”添加到 local-host-names 文件中
4. 开启sendmail服务器的网络接口
cp sendmail.mc sendmail.mc.bak 为了防止出错,备份配置文件
vim /etc/mail/sendmail.mc
查 找:DAEMON_OPTIONS(`Port=smtp,Addr=127.0.0.1, Name=MTA')dnl
修改为:DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl
5. 设置SMTP的用户认证
vim /etc/mail/sendmail.mc
查找:
dnl 52 TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 login PLAIN')dnl
dnl 53 define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
去掉前面注释:“dnl”
在sendmail服务器中使用了saslauthd服务程序提供用户认证功能,所以要开启它
chkconfig --level 35 saslauthd on
service saslauthd start
6. 生成sendmail.cf文件
cd /etc/mail
m4 sendmail.mc > sendmail.cf
service sendmail restart
7. 用户管理
groupadd mailuser /* 建立邮件用户组*/
useradd -g mailuser -s /sbin/nologin mike /*建立不能登录系统的邮件用户*/
vim /etc/aliases /*sendmail使用aliases机制实现邮件别名和群发功能*/
admin: mike /*admin是mike的别名*/
testgroup: mike,john,tom,jack /*邮件群发,向testgroup邮箱发送就是向4个人发送*/
newaliases /*对aliases.db数据库更新*/
8. 安装POP3,IMAP功能
yum install dovecot
vim /etc/dovecot.conf
查 找:protocols = imap imaps
修改为:protocols = imap imaps pop3 pop3s
chkconfig --level 35 dovecot on
service dovecot restart
到这里sendmail已经配置完成,开启服务器后,可以用outlook邮件客户端软件进行收发邮件。下面在介绍openwebmail的安装:
9. 安装openwebmail
下载所需软件包: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. 初始化openwebmail系统
/var/www/cgi-bin/openwebmail/openwebmail-tool.pl --init
11. 修改配置文件
vim /var/www/cgi-bin/openwebmail/etc/openwebmail.conf
domainnames linux.com
default_language zh_CN.GB2312
default_iconset Cool3D.Chinese.Simplified
12. 安装Perl的FastCGI模块
下载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
或者:yum install perl-FCGI-ProcManager
13. 配置Perl的FastCGI脚本(perl-fast)
vim /etc/init.d/perl-fast
#!/usr/bin/perl -w
use FCGI;
use Socket;
use FCGI::ProcManager;
sub shutdown { 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 after exec'ing perl scripts
END() { }
BEGIN() { }
{
no warnings;
*CORE::GLOBAL::exit = sub { die "fakeexit\nrc=" . shift() . "\n"; };
};
eval q{exit};
if ($@) {
exit unless $@ =~ /^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", 10 );
#foreach $item (keys %env) { delete $ENV{$item}; }
#..fastcgi........
my $n_processes = $ENV{FCGI_NPROCESSES} || 4;
$proc_manager = FCGI::ProcManager->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 have 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 ( $request->accept() >= 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 < $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 app
if (
( -x $req_params{SCRIPT_FILENAME} ) && #can I execute this?
( -s $req_params{SCRIPT_FILENAME} ) && #Is this file empty?
( -r $req_params{SCRIPT_FILENAME} ) #can I read this file?
)
{
pipe( CHILD_RD, PARENT_WR );
pipe( PARENT_ERR, CHILD_ERR );
my $pid = open( CHILD_O, "-|" );
unless ( defined($pid) ) {
print("Content-type: text/plain\r\n\r\n");
"Error: CGI app returned no output - Executing $req_params{SCRIPT_FILENAME} failed !\n";
next;
}
$oldfh = select(PARENT_ERR);
$| = 1;
select(CHILD_O);
$| = 1;
select($oldfh);
if ( $pid > 0 ) {
close(CHILD_RD);
close(CHILD_ERR);
print 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 = $rin;
$nfound = 0; while ( $nfound =
select( $rout = $rin, undef, $ein = $eout, 10 ) )
{
die "$!" unless $nfound != -1;
$r1 = vec( $rout, fileno(PARENT_ERR), 1 ) == 1;
$r2 = vec( $rout, fileno(CHILD_O), 1 ) == 1;
$e1 = vec( $eout, fileno(PARENT_ERR), 1 ) == 1;
$e2 = vec( $eout, fileno(CHILD_O), 1 ) == 1; if ($r1) {
while ( $bytes = read( PARENT_ERR, $errbytes, 4096 ) ) {
print STDERR $errbytes;
} if ($!) {
$err = $!;
die $!;
vec( $rin, fileno(PARENT_ERR), 1 ) = 0
unless ( $err == EINTR or $err == EAGAIN );
}
}
if ($r2) {
while ( $bytes = read( CHILD_O, $s, 4096 ) ) {
print $s;
}
if ( !defined($bytes) ) {
$err = $!;
die $!;
vec( $rin, fileno(CHILD_O), 1 ) = 0
unless ( $err == EINTR or $err == EAGAIN );
}
}
last if ( $e1 || $e2 );
}
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 directory
if ( $req_params{SCRIPT_FILENAME} =~ /^(.*)\/[^\/]+$/ ) {
chdir $1;
}
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} );
die("exec failed");
}
} else {
print("Content-type: text/plain\r\n\r\n");
"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
添加以下内容:
export FCGI_SOCKET_PATH="/tmp/perl-fastcgi.sock"
export FCGI_NPROCESSES=4
执行perl-fast脚本,在后台运行。
source /etc/profile
/etc/init.d/perl-fast &
14. 配置enable_perl.conf文件,文件放在 nginx/conf 目录下。内容如下:
#enable openwebmail fastcgi_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 60;
然后为Nginx添加FastCGI的Perl支持
server {
listen 80;
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. 在web服务器中发布openwebmail
为了浏览器中不用输入很长的地址,做一个引导页
vim /var/www/index.php
<script language=javascript>
location.href="cgi-bin/openwebmail/openwebmail.pl";
</script>
16. 文件权限的设置
#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
配置完毕,测试和如何使用我想应该不用多韶了!
LNMP环境下SendMail+OpenWebMail的详细配置的更多相关文章
- 记一次lnmp环境下无法执行php文件
lnmp环境搭建好后却无法正常执行php文件,坑爹啊!~ [错误状况] 页面直接打印出php代码内容: php文件无法执行?: 查看nginx配置文件: server { listen 80; ser ...
- thinkphp 5.0 lnmp环境下 无法访问,报错500(public目录)
两种方法: 1.修改fastcgi的配置文件 /usr/local/nginx/conf/fastcgi.conf fastcgi_param PHP_ADMIN_VALUE "open_b ...
- linux lnmp环境下 安装apache教程
linux lnmp环境下 安装apache教程 源码安装 apr ,apr-util 安装apache要用<pre>wget http://mirrors.cnnic.cn/apache ...
- Windows环境下MongoDB的安装与配置
MongoDB是一种高性能的文档型数据库,现介绍一下在Windows环境下MongDB的安装与配置 获取MongoDB 打开官方网站 www.mongodb.org,找到页面右上解的DownLoad链 ...
- qt5.11.2+vs2017环境下opencv3.4.1编译配置
OpenCV是一个开源的计算机库,它可以帮助视觉工作者做很多富有创造性的工作,在图像处理领域扮演着重要的角色.由于opencv3.x的存在,不管你是学生还是研究人员,是专家还是初学者,都可以快速的建立 ...
- 实验五:Xen环境下多虚拟机的桥接配置
实验名称: Xen环境下多虚拟机的桥接配置 实验环境: 这里我们首先需要有一台已经安装好的虚拟机机,能够正常运行,且网卡正常,如下图: 实验需求: 进行虚拟机的复制,并添加新的网桥配置,然后将两台虚拟 ...
- linux搭建的LNMP环境下的mysql授权远程连接
用phpstudy搭建的lnmp环境下mysql授权远程连接 简单高效 这是因为mysql 里的优先级不是所有人(提前检查防火墙是关闭状态)1.使用phpstudy安装的mysql没有放置到可以直接调 ...
- Ubuntu系统下lnmp环境搭建和Nginx多站点配置
最近需要使用Ubuntu作为服务器搭建Lnmp环境,顺便将操作过程写下来,与大家分享.如有不足之处,欢迎大家提出不同意见.(本文默认读者已经熟悉相关linux命令的使用,比如创建文件和文件夹,编辑文件 ...
- 全网最详细的大数据集群环境下如何正确安装并配置多个不同版本的Cloudera Hue(图文详解)
不多说,直接上干货! 为什么要写这么一篇博文呢? 是因为啊,对于Hue不同版本之间,其实,差异还是相对来说有点大的,具体,大家在使用的时候亲身体会就知道了,比如一些提示和界面. 全网最详细的大数据集群 ...
随机推荐
- HDUOJ--1874 畅通工程续
畅通工程续 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- iOS_21团购_Popover适应iPad横竖屏切换
终于效果图: 代码片段: // // DockItemLocation.m // 帅哥_团购 // // Created by beyond on 14-8-13. // Copyright (c) ...
- SpringSecurityFilter 链
1. HttpSessionContextIntegrationFilter 位于过滤器顶端,第一个起作用的过滤器. 用途一,在执行其他过滤器之前,率先判断用户的session中是否已经存在一个Sec ...
- ps钢笔工具 (重要工具)
ps钢笔工具 ctrl键 + 鼠标选中操作的点 = 移动点 alt键 + 方点 + 拖拉 = 拖出两个手柄 和 控制两端弧度 alt键 + 圆点 = 控制单向弧度
- [sql]大型网站MySQL深度优化揭秘
大型网站MySQL深度优化揭秘 第1章优化的思路和线路 1.1 网站优化的思路 2 1.2 MySQL优化,nginx这样的东西怎么优化? 第2章硬件层面优化 2.1 数据库物理机 2.1.1 ...
- linux kernel & source code analysis& hacking
https://kernelnewbies.org/ http://www.tldp.org/LDP/lki/index.html https://kernelnewbies.org/ML https ...
- ny214 单调递增子序列(二) 动态规划
单调递增子序列(二) 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 给定一整型数列{a1,a2...,an}(0<n<=100000),找出单调递增最长子序 ...
- Apache Commons Lang的StringUtils.isEmpty(STR)和StringUtils.isBlank(STR)
Apache Commons Lang是常用的基础框架,其中字符串判空在项目中尤为常用,而自己常常忘记他们的区别. package com.nicchagil.test; import org.apa ...
- display与visibility的区别
style.visibility和style.display都可以实现对页的隐藏,但visibility要占用域的空间,而display则不占用 将元素display属性设为 block,会在该元素后 ...
- LeetCode: Valid Number 解题报告
Valid NumberValidate if a given string is numeric. Some examples:"0" => true" 0.1 ...