简单搭建自己的邮件服务器-chasquid

chasquid 是golang 写的一个简单的smtp服务器

记录操作步骤:

设置DNS

; Assign “mail.example.com” to the server’s IP addresses.
; Replace these with the ones for your server.
mail A 198.51.100.7
mail AAAA 2001:db8::7

; The mail server for example.com is mail.example.com.
@ MX 10 mail

; Use SPF to say that the servers in “MX” above are allowed to send email
; for this domain, and nobody else.
@ TXT “v=spf1 mx -all”

安装chasquid

sudo apt install chasquid

添加用户:

chasquid-util user-add [email protected]

添加ssl证书

创建mail.example.com的SSL证书。然后放到:
/etc/chasquid/certs/mail.example.com下面,命名按下面改一下。

The configuration is in /etc/chasquid/ by default, and has the following structure:

  • chasquid.conf Main config file.

  • domains/ Domains’ data.

    • example.com/
      • users User and password database for the domain.
      • aliases Aliases for the domain.
  • certs/ Certificates to use, one dir per pair.

    • mail.example.com/
      • fullchain.pem Certificate (full chain).
      • privkey.pem Private key.

检查

chasquid-util print-config

smtp-check example.com

注意主机防火墙要打开:465 587端口。

smtp发送邮件测试:

package main

import (
	"fmt"
	"net/smtp"
)

func main() {
	addr := "mail.xx.com:587"
	auth := smtp.PlainAuth("", "[email protected]", "xx", "mail.xx.com")
	from := "[email protected]"
	to := []string{"[email protected]"}
	msg := []byte("To: [email protected]\r\n" +
		"Subject: test!\r\n" +
		"\r\n" +
		"This is the email body.\r\n")
	err := smtp.SendMail(addr, auth, from, to, msg)
	fmt.Println(err)
}

推荐国民远程控制软件KKVIEW: https://www.kkview.com
一键控制公司/家电脑/手机.

收邮件

[email protected] 收到的邮件会转发到这个邮箱。
/etc/chasquid/domain/example.com/aliases 里面加入转发:
user: [email protected]

imap

如果需要imap pop3,需要配置这个了:

Configure dovecot
First, install dovecot, and let chasquid use it for authorizing users. That way, you will only use a single system for managing users (dovecot).

sudo apt install dovecot-imapd dovecot-pop3d dovecot-lmtpd

cat <<EOF | sudo tee /etc/dovecot/conf.d/11-chasquid.conf
### Allow chasquid to authorize users via dovecot.
service auth {
  unix_listener auth-chasquid-userdb {
    mode = 0660
    user = chasquid
  }
  unix_listener auth-chasquid-client {
    mode = 0660
    user = chasquid
  }
}
EOF
You will need to configure dovecot authentication depending on your needs. For example, if you want to use only system users, or virtual users. See the /etc/dovecot/conf.d/10-auth.conf file, and the dovecot documentation for more details.

域名反向解析服务,TX云太坑收费。不搞 了。

排错:

启动错误, 如果出现users文件无法读取。请设置它的权限。

收信,出现no maildrop 错误,需要安装dovecot。

推荐国民远程控制软件KKVIEW,一键控制公司/家电脑/手机.

你可能感兴趣的:(Go,myself,golang,smtp,邮件服务器)