mail.ewomail.com、ewomail.com,需要改成你自己的域名
111.111.1.11,需要改成你自己的ip
域名DNS配置
1:@ewomail.com
记录类型:MX
优先级:填写数字,随便填,我填写的是10
主机:mail.ewomail.com
2:@ewomail.com
记录类型:TXT
TXT:v=spf1 111.111.1.11 -all
3:mail.ewomail.com
记录类型:A
IP地址:111.111.1.11
4:smtp.ewomail.com
记录类型:CHAME
IP地址:mail.ewomail.com
5:pop.ewomail.com
记录类型:CHAME
IP地址:mail.ewomail.com
6:imap.ewomail.com
记录类型:CHAME
IP地址:mail.ewomail.com
7:dkim._domainkey.ewomail.com
记录类型:TXT
TXT:待定,后续docker启动后会有的
运行docker
其中mail.ewomail.com需要替换成自己的域名
docker-compose-app.yml里的内容:
version: '3' services: ewomail: image: bestwu/ewomail hostname: mail.ewomail.com container_name: ewomail restart: always ports: - "25:25" - "109:109" - "110:110" - "143:143" - "465:465" - "587:587" - "993:993" - "995:995" - "8010:80" - "8011:8080" volumes: - ./ewomail/mysql:/ewomail/mysql/data - ./ewomail/vmail:/ewomail/mail - ./ewomail/rainloop:/ewomail/www/rainloop/data - ./ewomail/ssl/certs/:/etc/ssl/certs/ - ./ewomail/ssl/private/:/etc/ssl/private/ - ./ewomail/ssl/dkim/:/ewomail/dkim/
需要开放一下对应的端口:25、109、110、143、465、587、993、995、8010、8011
如果部署遇到25端口被占用,可通过netstat -apn|grep 25
查看是否是postfix导致,CentOS7可卸载postfix,卸载命令:yum -y remove postfix
运行成功后访问
邮箱管理后台
链接:http://mail.ewomail.com:8011
默认用户: admin
默认密码: ewomail123
Rainloop管理端
链接:http://mail.ewomail.com:8010?admin
默认用户: admin
默认密码: 12345
Rainloop用户端
链接:http://mail.ewomail.com:8010
用户名和密码,需要在[邮箱管理后台]中创建
这里的链接访问一定要用mail.ewomail.com,而不是ip,否则登录时会一直登录不上
获取dkim._domainkey.ewomail.com的TXT信息
执行docker命令查看代码
docker exec ewomail amavisd showkeys
若安装成功,则会提示:
; key#1, domain bodeqi.xyz, /ewomail/dkim/mail.pem
dkim._domainkey.bodeqi.xyz. 3600 TXT (
"v=DKIM1; p="
"MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDV2qKBo08WtNzj+rKT2YvKQbrI"
"9bQpkm/H0pkd7ZI1YCMIMZArJpkfxyWsh+VoSoiOcqTfrzieXcqjnx46G5Evg1FG"
"AQVk2AF6ATR9vqmVuUYawRLBzVvzLC2rfjnRXlsWwDeSEhCENWJluezD7Hzw5qmH"
"sKNGxxorpULkS3SnkQIDAQAB")
复制输出的信息,打开 DKIM整理 - EwoMail邮件服务器 ,整理DKIM,得到记录值:
v=DKIM1;p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDV2qKBo08WtNzj+rKT2YvKQbrI9bQpkm/H0pkd7ZI1YCMIMZArJpkfxyWsh+VoSoiOcqTfrzieXcqjnx46G5Evg1FGAQVk2AF6ATR9vqmVuUYawRLBzVvzLC2rfjnRXlsWwDeSEhCENWJluezD7Hzw5qmHsKNGxxorpULkS3SnkQIDAQAB
把这记录值贴到DNS解析中的第7点中即可。
等待10分钟后测试是否设置正确。
docker exec ewomail amavisd testkeys
如果提示:TESTING#1: dkim._domainkey.ewomail.com => pass,显示pass则正确。
EwoMail配置
1、进入容器:docker exec -it ewomail bash
修改 main.cf 配置文件:vi /etc/postfix/main.cf
注释以下行(在文件最后几行):
# content_filter = smtp-amavis:[127.0.0.1]:10024
2、修改/etc/hosts为以下内容
127.0.0.1 VM_0_17_centos VM_0_17_centos 127.0.0.1 localhost.localdomain localhost 127.0.0.1 localhost4.localdomain4 localhost4 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 127.0.0.1 mail.ewomail.com ewomail.com smtp.ewomail.com imap.ewomail.com //ewomail.com需要改为你自己的域名 ::1 VM_0_17_centos VM_0_17_centos ::1 localhost.localdomain localhost ::1 localhost6.localdomain6 localhost6
3.修改配置文件:vi /ewomail/www/ewomail-admin/core/config.php
修改以下内容
'url'=>'http://mail.ewomail.com:8011'
'webmail_url'=>'http://mail.ewomail.com:8010'
使用JAVA代码读取邮件
import javax.mail.*; import javax.mail.internet.MimeMultipart; import java.io.IOException; import java.util.Properties; public class MailUtil { public static void main(String[] args) { getCode("aaa01@ewomail.com", "123456789"); } public static String getCode(String email, String password) { String host = "imap.ewomail.com"; Properties properties = new Properties(); properties.put("mail.imap.host", host); properties.put("mail.imap.port", "143"); // IMAP SSL端口通常是993 properties.put("mail.imap.ssl.enable", "false"); // 不启用SSL Session session = Session.getDefaultInstance(properties); String code = null; try { Store store = session.getStore("imap"); // 使用IMAP协议 store.connect(host, email, password); Folder inbox = store.getFolder("INBOX"); inbox.open(Folder.READ_ONLY); Message[] messages = inbox.getMessages(); for (Message message : messages) { String content = MailUtil.getTextFromMessage(message); System.out.println(content); } inbox.close(false); store.close(); } catch (Exception e) { e.printStackTrace(); } return null; } private static String getTextFromMessage(Message message) throws MessagingException, IOException { String result = ""; if (message.isMimeType("text/plain")) { result = message.getContent().toString(); } else if (message.isMimeType("multipart/*")) { MimeMultipart mimeMultipart = (MimeMultipart) message.getContent(); result = getTextFromMimeMultipart(mimeMultipart); } return result; } private static String getTextFromMimeMultipart(MimeMultipart mimeMultipart) throws MessagingException, IOException { StringBuilder result = new StringBuilder(); int count = mimeMultipart.getCount(); for (int i = 0; i < count; i++) { BodyPart bodyPart = mimeMultipart.getBodyPart(i); if (bodyPart.isMimeType("text/plain")) { result.append(bodyPart.getContent()); } else if (bodyPart.isMimeType("text/html")) { String html = (String) bodyPart.getContent(); result.append(org.jsoup.Jsoup.parse(html).text()); } else if (bodyPart.getContent() instanceof MimeMultipart) { result.append(getTextFromMimeMultipart((MimeMultipart) bodyPart.getContent())); } } return result.toString(); } }
aaa01@ewomail.com、123456789,是在[邮箱管理后台:http://mail.ewomail.com:8011]中添加的
代码中也没有启用ssl,暂时没去研究,后续研究了将会补上。有不足的希望大佬们指点一下。