目次

メールサーバの構築

今回は旧学科メールサーバからの転送を受け取るだけのサーバを立てることにする。

Postfixのインストール

インストールはapt一発とはいかない。(Ubuntu Serverの場合)

$ sudo apt install postfix
$ sudo apt install mailutils # デフォルトでmailコマンドが入ってないなんて!

途中で

Package configuration
 
  ┌────────────────────────┤ Postfix Configuration ├────────────────────────┐
  │                                                                         │
  │ Please select the mail server configuration type that best meets your
  │ needs.
  │
  │  No configuration:
  │   Should be chosen to leave the current configuration unchanged.
  │  Internet site:
  │   Mail is sent and received directly using SMTP.
  │  Internet with smarthost:
  │   Mail is received directly using SMTP or by running a utility such
  │   as fetchmail. Outgoing mail is sent using a smarthost.
  │  Satellite system:
  │   All mail is sent to another machine, called a 'smarthost', for
  │   delivery.
  │  Local only:
  │   The only delivered mail is the mail for local users. There is no
  │   network.
  │
  │                                 <Ok>
  │                                                                         │
  └─────────────────────────────────────────────────────────────────────────┘

のような選択肢が出るので、ここはLocal onlyを選択する。

 ┌─────────────────────────┤ Postfix Configuration ├─────────────────────────┐
 │ The 'mail name' is the domain name used to 'qualify' _ALL_ mail           │
 │ addresses without a domain name. This includes mail to and from <root>:   │
 │ please do not make your machine send out mail from root@example.org       │
 │ unless root@example.org has told you to.                                  │
 │                                                                           │
 │ This name will also be used by other programs. It should be the single,   │
 │ fully qualified domain name (FQDN).                                       │
 │                                                                           │
 │ Thus, if a mail address on the local host is foo@example.org, the         │
 │ correct value for this option would be example.org.                       │
 │                                                                           │
 │ System mail name:                                                         │
 │                                                                           │
 │ XXX.XXX.XXX.ac.jp_________________________________________________________ │
 │                                                                           │
 │                    <Ok>                        <Cancel>                   │
 │                                                                           │
 └───────────────────────────────────────────────────────────────────────────┘

これでXXX@XXX.XXX.XXX.ac.jp宛のメールを受け取ることができる。

Setting-up Postfix

設定ファイルは/etc/postfix/main.cf。(雛形が/usr/share/postfixにある。)

変更はpostconfを使って

$ sudo postconf smtpd_banner=\$myhostname\ ESMTP\ \$mail_name

のように行う。

パラメータデフォルト設定値
myorigin$myhostname
mydestination$myhostname localhost.$mydomain localhost
inet_interfaceslocal-loopback

あたりの設定が必要。 最終的に、外からアクセスして以下のようなレスポンスが返ってくるようになってればOK。

% telnet mail.global.jp 25
Trying XXX.XX.XX.XXX...
Connected to mail.global.jp.
Escape character is '^]'.
220 mail.local ESMTP Postfix (Ubuntu)
mail from: xyz@abc.net
250 2.1.0 Ok
rcpt to: user@mail.global.jp
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
This mail comes from outside.
.
250 2.0.0 Ok: queued as D186F80AFD
quit
221 2.0.0 Bye
Connection closed by foreign host.
% telnet mail.global.jp 25
Trying XXX.XX.XX.XXX...
Connected to mail.global.jp.
Escape character is '^]'.
220 mail.local ESMTP Postfix (Ubuntu)
mail from: xyz@abc.net
250 2.1.0 Ok
rcpt to: user@somewhere.else.jp
454 4.7.1 <user@somewhere.else.jp>: Relay access denied
quit
221 2.0.0 Bye
Connection closed by foreign host.
% 

dovecot

インストールはapt一発。(Ubuntu Serverの場合)

$ sudo apt install dovecot-imapd

設定ファイルは/etc/dovecot/dovecot.conf

main.cfのパラメータ

雛形 設定変更
#mail_owner = postfixmail_owner = postfix
#myhostname = host.domain.tldmyhostname = mail.local
#mydomain = domain.tld#mydomain = domain.tld
#myorigin = $mydomain#myorigin = $mydomain
#inet_interfaces = all#inet_interfaces = all
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#local_recipient_maps = unix:passwd.byname $alias_maps#local_recipient_maps = unix:passwd.byname $alias_maps
#home_mailbox = Maildir/#home_mailbox = Maildir/
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
sendmail_path =sendmail_path =
newaliases_path =newaliases_path =
mailq_path =mailq_path =
setgid_group =setgid_group =
html_directory =html_directory =
manpage_directory =manpage_directory =
sample_directory =sample_directory =
readme_directory =readme_directory =