Postfixを導入してメール送信専用のサーバーを構築します。
Ubuntu 20.02のroot環境で作業します。
Postfixが存在しないか確認します。
[root@ubuntu2004 ~]# systemctl status postfix
Unit postfix.service could not be found.
「y」を押してPostfixをインストールします。
# apt install postfix
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
libfwupdplugin1
Use 'apt autoremove' to remove it.
The following additional packages will be installed:
ssl-cert
Suggested packages:
procmail postfix-mysql postfix-pgsql postfix-ldap postfix-pcre postfix-lmdb
postfix-sqlite sasl2-bin | dovecot-common postfix-cdb mail-reader
postfix-doc openssl-blacklist
The following NEW packages will be installed:
postfix ssl-cert
0 upgraded, 2 newly installed, 0 to remove and 109 not upgraded.
Need to get 1,218 kB of archives.
After this operation, 4,642 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
「Internet Site」を選択してEnterします。
「OK」を選択してEnterします。
Postfixのインストールが完了しました。
Get:1 http://jp.archive.ubuntu.com/ubuntu focal/main amd64 ssl-cert all 1.0.39 [17.0 kB]
Get:2 http://jp.archive.ubuntu.com/ubuntu focal-updates/main amd64 postfix amd64 3.4.13-0ubuntu1.2 [1,201 kB]
Fetched 1,218 kB in 2s (542 kB/s)
Preconfiguring packages ...
Selecting previously unselected package ssl-cert.
(Reading database ... 157472 files and directories currently installed.)
Preparing to unpack .../ssl-cert_1.0.39_all.deb ...
Unpacking ssl-cert (1.0.39) ...
Selecting previously unselected package postfix.
Preparing to unpack .../postfix_3.4.13-0ubuntu1.2_amd64.deb ...
Unpacking postfix (3.4.13-0ubuntu1.2) ...
Setting up ssl-cert (1.0.39) ...
Setting up postfix (3.4.13-0ubuntu1.2) ...
Adding group `postfix' (GID 122) ...
Done.
Adding system user `postfix' (UID 115) ...
Adding new user `postfix' (UID 115) with group `postfix' ...
Not creating home directory `/var/spool/postfix'.
Creating /etc/postfix/dynamicmaps.cf
Adding group `postdrop' (GID 123) ...
Done.
setting myhostname: ubuntu2004
setting alias maps
setting alias database
mailname is not a fully qualified domain name. Not changing /etc/mailname.
setting destinations: $myhostname, ubuntu2004, localhost.localdomain, , localhost
setting relayhost:
setting mynetworks: 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
setting mailbox_size_limit: 0
setting recipient_delimiter: +
setting inet_interfaces: all
setting inet_protocols: all
/etc/aliases does not exist, creating it.##################################################.....................]
WARNING: /etc/aliases exists, but does not have a root alias.
Postfix (main.cf) is now set up with a default configuration. If you need to
make changes, edit /etc/postfix/main.cf (and others) as needed. To view
Postfix configuration values, see postconf(1).
After modifying main.cf, be sure to run 'systemctl reload postfix'.
Running newaliases
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /lib/systemd/system/postfix.service.
Processing triggers for ufw (0.36-6ubuntu1) ...
Rules updated for profile 'Nginx Full'
Processing triggers for systemd (245.4-4ubuntu3.16) ...
Processing triggers for man-db (2.9.1-1) ...
Processing triggers for rsyslog (8.2001.0-1ubuntu1.3) ...
Processing triggers for libc-bin (2.31-0ubuntu9.7) ...
Postfixのひとまずmain.cfファイルを編集します。
今回は自動送信専用のサーバーにするためポートは開けずローカルからのみ接続できるようにします
設定ファイル編集前にバックアップを作成してから作業します
作業内容の差分が以下
# cd /etc/postfix
diff main.cf main.cf.bak
45,46c45
< #inet_interfaces = all
< inet_interfaces = localhost
< #inet_protocols = all
< inet_protocols = ipv4
---
> inet_interfaces = all
> inet_protocols = all
Postfixを再起動して設定を反映します。
# systemctl restart postfix
Postfixの起動確認をします。起動しています。
# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
Loaded: loaded (/lib/systemd/system/postfix.service; enabled; vendor preset: enabled)
Active: active (exited) since Sun 2023-02-12 11:27:47 JST; 47s ago
Process: 1529167 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 1529167 (code=exited, status=0/SUCCESS)
Feb 12 11:27:47 ubuntu2004 systemd[1]: Starting Postfix Mail Transport Agent.
最後にサーバーがリブートした時に自動起動するように設定しておきます。
# systemctl enable postfix
Synchronizing state of postfix.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable postfix
Laravelからメール送信できるかを確認