ubuntu自己搭建邮件服务器

http://www.ixpub.net/thread-672704-1-1.html

Ubuntu+Sendmail+Dovecot+Openwebmail搭建邮件服务器

 1.安装apache

    apt-get install apache2

2.安装sendmail

     apt-get install sendmail

      #sasl2-bin已经同时安装,如果自己安装需要将/etc/default/saslauthd start=no 改为yes才能启动服务。

2.1设定Relay IP

     在/etc/mail/access中添加允许Relay的地址

      Connect:192.168.0 RELAY    #允许192.168.0.0网络的IP地址通过sendmail发信,也可以写成192.168.0

2.2设置收信的域名

    在/etc/mail/local-host-names中添加收信的域名

   ssh.tw

    mail.ssh.tw

    接收发往ssh.tw域和mail.ssh.tw域的邮件

2.3设置sendmail侦听范围,默认只侦听本机

   编辑/etc/mail/sendmail.mc,按照下边内容修改:

   DAEMON_OPTIONS(`Family=inet, Name=MTA-v4, Port=smtp, Addr=0.0.0.0′)dnl

   DAEMON_OPTIONS(`Family=inet, Name=MSP-v4, Port=submission, M=Ea, Addr=0.0.0.0′)dnl

   修改完成后使用一下命令使修改生效:

    m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

2.5重启sendmail服务

    /etc/init.d/sendmail restart

3.安装pop3服务

    3.1需要的包:dovecot-common,dovecot-pop3d

         apt-get install dovecot-common dovecot-pop3d

   3.2修改配置文件/etc/dovecot/dovecot.conf(不使用ssl配置方法)

    protocols = pop3
    disable_plaintext_auth = no

   ssl=no

   mail_location = mbox:/var/mail:INBOX=/var/mail/%u

3.3重启dovecot服务

      /etc/init.d/dovecot restart

3.4测试能否正常使用

   telnet pop3_server 110

   auth
  user user_name

   pass user_password

    提示OK说明可以正常使用。

 

4.安装openwebmail

4.1下载openwebmail包

(地址:http://openwebmail.org/openwebmail/download/release/)

使用wget命令下载最新版的包到/tmp

4.2解压包到/var/www下

tar xvzf openwebmail.tar.gz -C /var/www

4.3安装所需要的包

apt-get install perl-suid    #不安装无法执行pl脚本

apt-get install libapache2-mod-perl2    #安装后apache2可以支持cgi程序

4.4修改cgi-bin的默认路径

编辑/etc/apache2/sites-available/default,修改下边两行:

ScriptAlias /cgi-bin/ /var/www/cgi-bin/

<Directory /var/www/cgi-bin>

修改后重启apache

/etc/init.d/apace2 restart

4.5配置openwebmail所需要的配置文件:

4.5.1将/var/www/cgi-bin/openwebmail/etc/default/auth_unix.conf

复制到/var/www/cgi-bin/openwebmail/etc目录下,并修改以下两行:

passwdfile_encrypted /etc/shadow

passwdmkdb none

4.5.2将/var/www/cgi-bin/openwebmail/etc/default/dbm.conf

复制到/var/www/cgi-bin/openwebmail/etc/目录下,并修改以下一行:

dbm_ext .pag

4.5.3修改/var/www/cgi-bin/openwebmail/etc/openwebmail.conf

mailspooldir /var/mail

ow_cgidir /var/www/cgi-bin/openwebmail

ow_cgiurl /cgi-bin/openwebmail

ow_htmldir /var/www/data/openwebmail

ow_htmlurl /data/openwebmail

default_language zh_CN.GB2312

default_iconset Cool3D.Chinese.Simplified    #写不正确的话不显示图片

4.6运行以下命令配置openwebmail

/var/www/cgi-bin/openwebmail/openwebmail-tool.pl –init

4.7设置软连接访问openwebmail

在/var/www下建立openwebmail文件夹并建立软连接

mkdir openwebmail

cd openwebmail

ln -s /var/www/data/openwebmail/redirect.html index.html

5.访问http://serverip/openwebmail就可以访问openwebmail了。

6.发送邮件需要smtp认证的单独设置

6.1先来看一下/usr/lib/sasl2/Sendmail.conf文件里面的内容应该是pwcheck_method:saslauthd,将这个 文件复制成smtpd.conf,这个文件也要在/usr/lib/sasl2/目录下:

cp Sendmail.conf smtpd.conf

6.2编辑sendmail.mc,添加以下两行

TRUST_AUTH_MECH(`DIGEST-MD5 LOGIN PLAIN’)
define(`confAUTH_MECHANISMS’,`DIGEST-MD5 LOGIN PLAIN’)

6.3使配置生效:

m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf

/etc/init.d/sendmail restart

/etc/init.d/saslauthd restart

6.4注意事项

配置好后,可以使用smtp验证发送邮件,不使用smtp验证也能够发送邮件

原因:发送和接收邮件在域内,如果发送的邮件地址不在域内,则可能是 /etc/mail/access文件未清空。

解决:将 /etc/mail/access文件清空。

要注意的一点:

修改任何配置,需要重新启动sendmail。

转载自: http://www.usefulshare.com/terry-an/ubuntu-sendmail-dovecot-openwebmail.html






-------------------------------------------------
sendmail配置

    邮箱用户的建立,可以用客户端收发邮件即正常  
     
    groupadd  mailgroup  
     
    useradd  -g mailgroup –s /sbin/nologin  wugk  
     
    passwd wugk 设置好密码即可。  
     
    Service  sendmail restart ;service dovecot restart ;service saslauthd restart 重启所有sendmail相关服务

六、配置openwebmail

* 邮件服务器需要网页访问:要实现访问地址为http://mail.linuxidc.com/ ,所以我们需要配置openwebmail,配置如下:前提是安装好httpd。

之前我们已经安装完了openwebmail,默认会生成/var/www/cgi-bin/openwebmail 这样一个文件夹,如果你的apache安装在其他目录,需要把openwebmail拷贝到相应目录下:

1、修改openwebmail配置如下:都是修改的内容:

[root@localhost ~]# vi  /var/www/cgi-bin/openwebmail/etc/dbm.conf

    dbm_ext                 .db  
     
    dbmopen_ext             .db  
     
    dbmopen_haslock         no  
     
    然后初始化 ./var/www/cgi-bin/openwebmail/openwebmail-too.pl –init 按Y即可

2、修改vi /var/www/cgi-bin/openwebmail/etc/defaults/dbm.conf

    dbm_ext                 .db  
     
    dbmopen_ext             .db  
     
    dbmopen_haslock         yes

3、修改vi /var/www/cgi-bin/openwebmail/etc/openwebmail.conf

    domainnames                    linuxidc.com  
     
    default_language                zh_CN.GB2312  
     
    default_iconset                 Cool3D.Chinese.Simplified

4、修改vi /var/www/cgi-bin/openwebmail/etc/default/openwebmail.conf

    domainnames             linuxidc.com  
     
    smtpserver              mail.linuxidc.com  
     
    authpop3_server         mail.linuxidc.com  
     
    然后再执行./var/www/cgi-bin/openwebmail/openwebmail-too.pl –init 按Y即可

 5、apache修改配置文件

以下是apache配置段供参考:

    <VirtualHost *:80>  
     
     ServerAdmin wugk@linuxidc.com  
     
     ServerName  mail.linuxidc.com  
     
     DocumentRoot /usr/local/apache-2.2.13/  
     
     ScriptAlias /cgi-bin/ "/usr/local/apache-2.2.13/cgi-bin/"
     
     <Directory /usr/local/apache-2.2.13/>  
     
     Options Indexes FollowSymLinks  
     
     AllowOverride None  
     
     Order allow,deny  
     
     Allow from all  
     
     </Directory>  
     
    RewriteEngine On  
     
    ProxyPreserveHost On  
     
    RewriteRule ^/$  http://mail.linuxidc.com/cgi-bin/openwebmail/openwebmail.pl [P,L,NC]  
     
    </VirtualHost>

配置完毕测试:你的做好DNS解析,遇到问题一点一滴解决,遇到的错误也很多,只有你真正去做了才会明白。

访问http://mail.linuxidc.com 页面如下:




--------------------------------------------
'编辑你的/etc/resolv.conf 里面加上nameserver 自己的IP
  DNS服务器的修改是即时生效的,但这种修改方法在重启电脑后ubuntu系统会自动重写/etc/resolv.conf文件,恢复默认的DNS








------------------------------------------------
如果遇到 SendMail的"Relaying denied. IP name lookup failed问题

解决问题

修改access文件,将本机ip加入后,问题解决!

具体方法

/etc/mail/access

加入

xxx.xxx.xxx.xxx    RELAY

-------------------------------------------------

综合来讲精华如下

/var/www/cgi-bin/openwebmail/openwebmail-tool.pl --init
/etc/init.d/sendmail restart
/etc/init.d/saslauthd restart
/etc/init.d/apache2 restart


安装完毕增添用户
groupadd  mailgroup  
useradd -g mailgroup -b /home/mailgroup/ -s /sbin/nologin guoxuechong
mkdir guoxuechong
chown guoxuechong guoxuechong/
passwd guoxuechong







----------------------------------------------------------
http://hi.baidu.com/yanbin_yu/blog/item/91191609da1326cc3bc7633d.html
openwebmail 用户分组


修改openwebmail.conf設定,多加入以下幾行

(less openwebmail.conf.help有以下參數設定的意義)
abook_globaleditable yes
ow_addressbooksdir %ow_etcdir%/addressbooks
global_filterbook %ow_etcdir%/filter.book
global_calendarbook %ow_etcdir%/calendar.book

初始化openwebmail
 /var/www/cgi-bin/openwebmail/openwebmail-tool.pl --init

設定global為系統的公用通訊錄設定者
 cd /var/www/cgi-bin/openwebmail/etc/addressbooks/
 chown global.global global (若無此檔案自建,不過2.52版會內建此檔與user global)
 chmod 644 global
 ln -s /var/www/cgi-bin/openwebmail/etc/addressbooks/global     /home/global/.openwebmail/webmail/address.book

最後使用global 登入openwebmail就可以修改公用通訊錄啦
 但是這樣也是太麻煩囉!所以寫兩支程式來解決









  • 3
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
要在Ubuntu 20.04上搭建免费邮件服务器,你可以使用Postfix作为邮件传输代理(MTA)和Dovecot作为邮件传输代理(IMAP/POP3)。 以下是简单的步骤: 1. 安装Postfix和Dovecot: ``` sudo apt update sudo apt install postfix dovecot-core dovecot-imapd dovecot-pop3d ``` 2. 配置Postfix: 在终端中输入以下命令,开始配置Postfix: ``` sudo dpkg-reconfigure postfix ``` 在配置向导中,选择"Internet Site"作为配置类型,并为你的邮件服务器输入域名。 3. 配置Dovecot: 编辑Dovecot的主配置文件: ``` sudo nano /etc/dovecot/dovecot.conf ``` 找到以下行并取消注释(删除行首的`#`): ``` !include_try /usr/share/dovecot/protocols.d/*.protocol ``` 保存并关闭文件。 4. 创建SSL证书(可选): 如果你希望启用安全连接(SSL/TLS),可以创建自签名的SSL证书。 ``` sudo openssl req -new -x509 -nodes -out /etc/ssl/certs/dovecot.pem -keyout /etc/ssl/private/dovecot.pem -days 365 ``` 5. 重启服务: ``` sudo systemctl restart postfix sudo systemctl restart dovecot ``` 现在,你的免费邮件服务器已经安装和配置完成。你可以使用邮件客户端(如Outlook、Thunderbird等)来连接服务器,并使用你的域名和相应的用户名和密码进行登录。 请注意,这只是一个基本的配置,你可能需要进一步调整和配置以满足你的具体需求。另外,确保你的服务器设置有适当的防火墙规则和安全措施,以保护你的邮件服务器免受恶意攻击。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值