3
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

メールサーバ構築・プライベートDNSサーバ利用

Last updated at Posted at 2024-02-11

初めに

  • これまで、比較的簡単なサーバを複数構築してきた
  • ぱっと見でも難易度の高そうなメールサーバにそろそろ挑戦してみたいと思った
  • 金がないので、いろいろやってみようと思う
  • きっとその過程で、知識と理解が深まるだろう???

今回のひとまずの流れ

適当に見つけたサイトを参考に問題ないところまで進める
詰まったらほかのサイトを参照していく

環境

  • EC2(AmazonLinux2023)
  • 22, 25, 110, 143, 587を開放する
  • DNSサーバはVPC内のもので代用したい()!!!
  • 今回は流れの確認もかねてIMAP,POP,SMTPをすべて同じインスタンスに入れる
  • メールの送信は同じVPC内のインスタンスから行う

実施記録(説明は本家参照、n数を増やす意味で参考にしてください)

導入

$ sudo yum -y update
$ sudo yum install postfix
$ rpm -qa | grep postfix
postfix-3.7.2-4.amzn2023.0.5.x86_64

postfixのversionが表示されたら問題なし

設定ファイルの編集

事前準備

# コピー
$ sudo cp /etc/postfix/main.cf{,.original}
# 内容が一致しているかの確認
$ diff /etc/postfix/main.cf /etc/postfix/main.cf.original

何も表示されない場合は、内容が一致しているらしい!!

編集を始める

$ sudo vi /etc/postfix/main.cf

完璧に一致しているのでこちら参照で、、、
設定に関しては、概要だけ置いておきます。

#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
#myhostname = host.domain.tld
#myhostname = virtual.domain.tld
myhostname = test-mail.koinunopochi.com(こんな感じで追加しました)
#myorigin = $myhostname
#myorigin = $mydomain
#myorigin = $myhostname
myorigin = $mydomain (先頭のコメントアウト "#" を外します)
mydestination = $myhostname, localhost.$mydomain, localhost
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
#mydestination = $myhostname, localhost.$mydomain, localhost (コメントアウト "#" します)
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain (先頭のコメント
アウト "#" を外します)
#mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain,
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table
#mynetworks = $config_directory/mynetworks
#mynetworks = hash:/etc/postfix/network_table
# vpcとlocalhostの値を記述した
mynetworks = 172.16.0.0/16, 127.0.0.0/8 (追加します)
#smtpd_banner = $myhostname ESMTP $mail_name
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
#smtpd_banner = $myhostname ESMTP $mail_name
#smtpd_banner = $myhostname ESMTP $mail_name ($mail_version)
smtpd_banner = $myhostname ESMTP unknown (追加します)
#home_mailbox = Mailbox
#home_mailbox = Maildir/
#home_mailbox = Mailbox
home_mailbox = Maildir/ (先頭のコメントアウト "#" を外します)
$ diff main.cf.original main.cf
100c100
<
---
> myhostname = test-mail.koinunopochi.com
122c122
< #myorigin = $mydomain
---
> myorigin = $mydomain
187,188c187,188
< mydestination = $myhostname, localhost.$mydomain, localhost
< #mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
---
> #mydestination = $myhostname, localhost.$mydomain, localhost
> mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
291a292
> mynetworks =  172.16.0.0/16, 127.0.0.0/8
447c448
< #home_mailbox = Maildir/
---
> home_mailbox = Maildir/
601a603
> smtpd_banner = $myhostname ESMTP unknown
# 構文チェック
$ sudo postfix check
# 自動起動設定
$ systemctl enable --now postfix
# 起動できているかの確認
$ systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
     Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; preset: disabled)
     Active: active (running) since Sun 2024-02-11 03:25:01 UTC; 32s ago
    Process: 27091 ExecStartPre=/usr/sbin/restorecon -R /var/spool/postfix/pid/master.pid (code=exited, status=255/E>
    Process: 27094 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
    Process: 27121 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
    Process: 27131 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)

本家サイトでは、IPv6もListenしていたが、とりあえず、IPv4は問題なくListenしているため良しとすることにした

$ ss -atn | grep 25
LISTEN    0      100        127.0.0.1:25            0.0.0.0:*

メールユーザー作成

# ユーザーが追加時に自動でMaildir形式メールボックス作成するように設定
$ sudo mkdir -p /etc/skel/Maildir/{new,cur,tmp}
# パーミッションの変更
$ sudo chmod -R 700 /etc/skel/Maildir/
# ユーザーの追加
$ sudo useradd test-mail
# pwdの設定今回はユーザー名と同じに設定
$ sudo passwd test-mail
Changing password for user test-mail.
New password:
BAD PASSWORD: The password contains the user name in some form
Retype new password:
passwd: all authentication tokens updated successfully.

# 自動でユーザーのディレクトリが作成されているかの確認
$ sudo ls -l /home/test-mail/Maildir/
total 0
drwx------. 2 test-mail test-mail 6 Feb 11 03:32 cur
drwx------. 2 test-mail test-mail 6 Feb 11 03:32 new
drwx------. 2 test-mail test-mail 6 Feb 11 03:32 tmp

動作確認

SMTPサーバを立てたインスタンス内で、行う

# インストール
$ yum install telnet -y
# SMTPサーバにアクセス
$ telnet localhost 25
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 test-mail.koinunopochi.com ESMTP unknown
# 入力する↓ 送信元メールアドレスの確認
helo localhost
250 test-mail.koinunopochi.com
# mail from: コマンドで送信元メールアドレスを入力
mail from:test-mail@koinunoppochi.com
250 2.1.0 Ok
# rcpt to: コマンドで送信先メールアドレスを入力
rcpt to:test-mail@koinunoppochi.com
250 2.1.5 Ok
# dataコマンド
data
354 End data with <CR><LF>.<CR><LF>
# 本文を入力する。段落をおとして[.]を入れることで、本文の終了を伝える
これは本文です。
this is a pen.
.
250 2.0.0 Ok: queued as A4A5C7838A
# セッションの終了
quit
221 2.0.0 Bye
Connection closed by foreign host.

これでもうすでにメールが送信できているようだ

$ sudo ls -l /home/test-mail/Maildir/new
total 0

遅れていなかったようだ、、、orz
qitaに書いていた記述を確認したところ、

220 test-mail.koinunopochi.com ESMTP unknown
# 入力する↓ 送信元メールアドレスの確認
helo localhost
250 test-mail.koinunopochi.com
# mail from: コマンドで送信元メールアドレスを入力
mail from:test-mail@koinunoppochi.com # <-ここでスペルミスをしている
250 2.1.0 Ok
# rcpt to: コマンドで送信先メールアドレスを入力
rcpt to:test-mail@koinunoppochi.com # <-ここでスペルミスをしている

そこで、タイポを修正してもう一度試したところ、きちんとファイルが作成されていることを確認した。

$ sudo ls -l /home/test-mail/Maildir/new
total 4
-rw-------. 1 test-mail test-mail 497 Feb 11 06:15 1707632143.Vca01I824be3M641517.ip-172-31-7-217.ap-northeast-1.compute.internal

# 中身の確認
$ sudo cat /home/test-mail/Maildir/new/1707632143.Vca01I824be3M641517.ip-172-31-7-217.ap-northeast-1.compute.internal
Return-Path: <test-mail@koinunopochi.com>
X-Original-To: test-mail@koinunopochi.com
Delivered-To: test-mail@koinunopochi.com
Received: from localhost (localhost [127.0.0.1])
        by test-mail.koinunopochi.com (Postfix) with SMTP id 60B477838A
        for <test-mail@koinunopochi.com>; Sun, 11 Feb 2024 06:15:17 +0000 (UTC)
Message-Id: <20240211061528.60B477838A@test-mail.koinunopochi.com>
Date: Sun, 11 Feb 2024 06:15:17 +0000 (UTC)
From: test-mail@koinunopochi.com

これは本文です。
this is a pen.

どうやらこれで、最低限のPostfixの動作確認が終了したようである。

IMAP/POP3サーバ構築(Dovecot)

適宜こちらを参照してほしい

# インストール
$ sudo yum install dovecot -y
# 確認
$ rpm -qa | grep dovecot
dovecot-2.3.20-1.amzn2023.0.1.x86_64

設定ファイルの編集

1./etc/dovecot/conf.d/10-mail.conf

# コピー
$ sudo cp /etc/dovecot/conf.d/10-mail.conf{,.original}
# 一緒か確認何も出なければok
$ diff /etc/dovecot/conf.d/10-mail.conf{.original,}
# メールの格納形式をMaildir形式に変更
#mail_location =
#mail_location =
# コメントアウトで行ける
mail_location = maildir:~/Maildir (追加します)

# 変更内容の確認
$ diff /etc/dovecot/conf.d/10-mail.conf{.original,}
24c24
< #   mail_location = maildir:~/Maildir
---
> mail_location = maildir:~/Maildir

2. /etc/dovecot/conf.d/10-auth.conf

# コピー
$ sudo cp /etc/dovecot/conf.d/10-auth.conf{,.original}
# 一緒か確認何も出なければok
$ diff /etc/dovecot/conf.d/10-auth.conf{.original,}
$ sudo vi /etc/dovecot/conf.d/10-auth.conf
# SSLを使用しない場合に必須。暗号化されていない認証を許可する
#disable_plaintext_auth = yes
#disable_plaintext_auth = yes
disable_plaintext_auth = no (追加します)
# 認証時のメカニズムの指定
# plainに加えてloginを追加する

# NOTE: See also disable_plaintext_auth setting.
auth_mechanisms = plain# NOTE: See also disable_plaintext_auth setting.
auth_mechanisms = plain login (付け加えます)
# 変更差分の確認
$ diff /etc/dovecot/conf.d/10-auth.conf{.original,}
10c10
< #disable_plaintext_auth = yes
---
> disable_plaintext_auth = no
100,101c100
< auth_mechanisms = plain
<
---
> auth_mechanisms = plain login

3. /etc/dovecot/conf.d/10-ssl.conf

# コピー
$ sudo cp /etc/dovecot/conf.d/10-ssl.conf{,.original}
# 一緒か確認何も出なければok
$ diff /etc/dovecot/conf.d/10-ssl.conf{.original,}
$ sudo vi /etc/dovecot/conf.d/10-ssl.conf
# SSlを使用しないため、メールクライアントと「dovecot」間のSSL接続を無効化する
ssl = requiredssl = no (書き換えます)

# 差分
$ diff /etc/dovecot/conf.d/10-ssl.conf{.original,}
8c8
< ssl = required
---
> ssl = no

4. /etc/dovecot/conf.d/10-master.conf

# コピー
$ sudo cp /etc/dovecot/conf.d/10-master.conf{,.original}
# 一緒か確認何も出なければok
$ diff /etc/dovecot/conf.d/10-master.conf{.original,}

認証ソケットライブラリを設定するとのこと

$ sudo vi /etc/dovecot/conf.d/10-master.conf

# Postfix smtp-auth
# unix_listener /var/spool/postfix/private/auth {
# mode = 0666
# }# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {   (コメントを外す)
mode = 0666  (コメントを外す)
user = postfix  (追記)
group = postfix  (追記)
}

# 差分
$ diff /etc/dovecot/conf.d/10-master.conf{.original,}
110,112c110,114
<   #unix_listener /var/spool/postfix/private/auth {
<   #  mode = 0666
<   #}
---
>   unix_listener /var/spool/postfix/private/auth {
>     mode = 0666
>     user = postfix
>     group = postfix
>   }

自動起動

$ $ sudo systemctl enable --now dovecot
# ステータス確認
$ systemctl status dovecot
● dovecot.service - Dovecot IMAP/POP3 email server
     Loaded: loaded (/usr/lib/systemd/system/dovecot.service; enabled; preset: disabled)
     Active: active (running) since Sun 2024-02-11 06:46:54 UTC; 24s ago
       Docs: man:dovecot(1)
             https://doc.dovecot.org/
   Main PID: 4595 (dovecot)
     Status: "v2.3.20 (80a5ac675d) running"

IMAP/POP3動作確認

指定したポートがListenになっていれば良いっぽい

$ ss -atn | grep 110
LISTEN 0      100          0.0.0.0:110        0.0.0.0:*
LISTEN 0      100             [::]:110           [::]:*
$ ss -atn | grep 143
LISTEN 0      100          0.0.0.0:143        0.0.0.0:*
LISTEN 0      100             [::]:143           [::]:*

POP3動作確認

$ telnet localhost 110
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
User test-mail
+OK
Pass test-mail
+OK Logged in.
LIST
+OK 1 messages:
1 509
.
RETR 1
+OK 509 octets
Return-Path: <test-mail@koinunopochi.com>
X-Original-To: test-mail@koinunopochi.com
Delivered-To: test-mail@koinunopochi.com
Received: from localhost (localhost [127.0.0.1])
        by test-mail.koinunopochi.com (Postfix) with SMTP id 60B477838A
        for <test-mail@koinunopochi.com>; Sun, 11 Feb 2024 06:15:17 +0000 (UTC)
Message-Id: <20240211061528.60B477838A@test-mail.koinunopochi.com>
Date: Sun, 11 Feb 2024 06:15:17 +0000 (UTC)
From: test-mail@koinunopochi.com

これは本文です。
this is a pen.
.
quit
+OK Logging out.
Connection closed by foreign host.

IMAP動作確認

1 login test-mail test-mail
のように入力するとき「1 」は必須です

$ telnet localhost 143
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
* OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE LITERAL+ AUTH=PLAIN AUTH=LOGIN] Dovecot ready.
1 login test-mail test-mail
1 OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SNIPPET=FUZZY PREVIEW=FUZZY PREVIEW STATUS=SIZE SAVEDATE LITERAL+ NOTIFY SPECIAL-USE] Logged in
2 list "" *
* LIST (\HasNoChildren) "." INBOX
2 OK List completed (0.001 + 0.000 secs).
3 select INBOX
* FLAGS (\Answered \Flagged \Deleted \Seen \Draft)
* OK [PERMANENTFLAGS (\Answered \Flagged \Deleted \Seen \Draft \*)] Flags permitted.
* 1 EXISTS
* 0 RECENT
* OK [UIDVALIDITY 1707634697] UIDs valid
* OK [UIDNEXT 2] Predicted next UID
3 OK [READ-WRITE] Select completed (0.001 + 0.000 secs).
4 fetch 1 body[]
* 1 FETCH (BODY[] {509}
Return-Path: <test-mail@koinunopochi.com>
X-Original-To: test-mail@koinunopochi.com
Delivered-To: test-mail@koinunopochi.com
Received: from localhost (localhost [127.0.0.1])
        by test-mail.koinunopochi.com (Postfix) with SMTP id 60B477838A
        for <test-mail@koinunopochi.com>; Sun, 11 Feb 2024 06:15:17 +0000 (UTC)
Message-Id: <20240211061528.60B477838A@test-mail.koinunopochi.com>
Date: Sun, 11 Feb 2024 06:15:17 +0000 (UTC)
From: test-mail@koinunopochi.com

これは本文です。
this is a pen.
)
4 OK Fetch completed (0.001 + 0.000 secs).
5 logout
* BYE Logging out
5 OK Logout completed (0.001 + 0.000 secs).
Connection closed by foreign host.

ここまでで、ローカル環境での設定は終わりらしい

Postfix追加設定

# コピー localまでの設定なので、拡張しをlocalにした
$ sudo cp /etc/postfix/main.cf{,.local}
# 内容が一致しているかの確認
$ diff /etc/postfix/main.cf{,.local}
$ sudo vi /etc/postfix/main.cf

#inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
inet_interfaces = localhost
↓
# メールの受け取りインターフェイスを指定する
# "all" を指定することで外部からのメールを受信できるようになる
inet_interfaces = all (コメントアウトを外します)
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost (コメントアウトします)

# プロトコルの変更
inet_protocols = all
↓
inet_protocols = ipv4 (書き換えます)

# 一番下に追記
smtpd_sasl_auth_enable = yes
smtpd_sasl_type = dovecot
smtpd_sasl_path = private/auth
smtpd_recipient_restrictions =
    permit_mynetworks
    permit_sasl_authenticated
    reject_unauth_destination

$ diff /etc/postfix/main.cf{,.local}
136c136
< inet_interfaces = all
---
> #inet_interfaces = all
139c139
< #inet_interfaces = localhost
---
> inet_interfaces = localhost
142c142
< inet_protocols = ipv4
---
> inet_protocols = all
750,758d749
<
< smtpd_sasl_auth_enable = yes
< smtpd_sasl_type = dovecot
< smtpd_sasl_path = private/auth
<
< smtpd_recipient_restrictions =
<     permit_mynetworks
<     permit_sasl_authenticated
<     reject_unauth_destination

SUBMISSION(587番ポートの有効化・認証設定)

$ sudo cp /etc/postfix/master.cf{,.original}
$ diff /etc/postfix/master.cf{,.original}

$ sudo vi /etc/postfix/master.cf

#submission inet n - n - - smtpd
↓
submission inet n - n - - smtpd (コメントアウトを外します)

# -o smtpd_sasl_auth_enable=yes# 上の行に合わせて、3こスペースが必要
-o smtpd_sasl_auth_enable=yes (コメントアウトを外します)

# 変更差分
$ diff /etc/postfix/master.cf{,.original}
19c19
< submission inet n       -       n       -       -       smtpd
---
> #submission inet n       -       n       -       -       smtpd
22c22
< -o smtpd_sasl_auth_enable=yes
---
> #  -o smtpd_sasl_auth_enable=yes

SMTP認証設定

$ sudo yum install cyrus-sasl
# 起動設定
$ sudo systemctl enable --now saslauthd
# postfixの再起動
$ systemctl restart postfix

# 認証機能が追加されているかの確認 下の表示ならok
$ postconf -a
cyrus
dovecot

# 動作確認1
$ ss -atn | grep 587
LISTEN    0      100          0.0.0.0:587           0.0.0.0:*

# 動作確認2
$ telnet localhost 587
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 test-mail.koinunopochi.com ESMTP unknown
ehlo localhost
250-test-mail.koinunopochi.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-AUTH PLAIN LOGIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-SMTPUTF8
250 CHUNKING
mail from:test-mail@koinunopochi.com
250 2.1.0 Ok
rcpt to:test-mail@koinunopochi.com
250 2.1.5 Ok
data
354 End data with <CR><LF>.<CR><LF>
test mail
.
250 2.0.0 Ok: queued as 6837778016
quit
221 2.0.0 Bye
Connection closed by foreign host.

# メールの確認
$ sudo ls -l /home/test-mail/Maildir/new/
total 4
-rw-------. 1 test-mail test-mail 468 Feb 11 09:22 1707643364.Vca01I824bc0M791220.ip-172-31-7-217.ap-northeast-1.compute.internal
# 中身の確認
$ sudo cat /home/test-mail/Maildir/new/1707643364.Vca01I824bc0M791220.ip-172-31-7-217.ap-
northeast-1.compute.internal
Return-Path: <test-mail@koinunopochi.com>
X-Original-To: test-mail@koinunopochi.com
Delivered-To: test-mail@koinunopochi.com
Received: from localhost (localhost [127.0.0.1])
        by test-mail.koinunopochi.com (Postfix) with ESMTP id 6837778016
        for <test-mail@koinunopochi.com>; Sun, 11 Feb 2024 09:22:22 +0000 (UTC)
Message-Id: <20240211092233.6837778016@test-mail.koinunopochi.com>
Date: Sun, 11 Feb 2024 09:22:22 +0000 (UTC)
From: test-mail@koinunopochi.com

test mail

ここまででメールサーバの設定は終わりらしい。。。

DNSの設定(本題)

本家のほうでは、Route 53を使用して公開して実施しているが、せっかく昨日VPC用のDNSサーバを立てたので、そこにレコードを登録して、クライエントEC2からメールが送れるような感じにしようと思う

流れの説明

※ 参考サイトに基本従う予定である

  1. 「設定したドメイン名」のホストゾーンの作成
  2. サーバのホスト名と固定IPでAレコードに登録
    1. サーバのホスト名とプライベートIPでAレコードに登録する
  3. ドメインとサーバーのホスト名でMXレコードを登録
  4. 最後にSPFレコードを登録
$TTL 43200
@       IN      SOA     help.koinunopochi.com. ns01.koinunopochi.com. (
                            1          ; serial
                            21600      ; refresh (6 hours)
                            7200       ; retry (2 hours)
                            1209600    ; expire (2 weeks)
                            43200 )    ; minimum (12 hours)

        IN      NS      ns01.koinunopochi.com.

ns01    IN      A       172.31.10.90
www     IN      A       172.31.10.90
# mailサーバのアドレスの追加
mail    IN      A       172.31.7.217
@       IN      MX      10 mail.koinunopochi.com.
# 今回はSPFの設定が難しかったため断念した

詳細はこちらからどうぞ

このあと、上の記事で作成していたDNSホストからの接続テストが途中から急に失敗することとなりました、、、

主な原因は、resolve.confの設定で再起動時に上書きされないようにする設定を忘れていたため、流れで再起動した結果、設定が上書きされてしまったためでした。

再度、resolve.confの設定を適切なものに変えたことで、無事にDNSの設定が完了しました。

最後にローカルホストではなく、別のインストールからのメール送信を試して終了としたいです。

mail.py
import smtplib
from email.mime.text import MIMEText
from email.header import Header

# SMTPサーバーの設定
smtp_server = 'mail.koinunopochi.com'
smtp_port = 25
smtp_user = 'test-mail'
smtp_password = 'test-mail'

# 送受信先
sender = 'test-mail@koinunopochi.com'
recipient = 'test-mail@koinunopochi.com'

# メールの内容
subject = 'Pythonからのテストメール'
body = 'これはPythonスクリプトから送信されたメールです。'

# MIMETextオブジェクトの作成
msg = MIMEText(body, 'plain', 'utf-8')
msg['From'] = sender
msg['To'] = recipient
msg['Subject'] = Header(subject, 'utf-8')

try:
    # SMTPサーバーへの接続
    server = smtplib.SMTP(smtp_server, smtp_port)
    # server.starttls()  # TLS(セキュリティ)を有効にする
    server.login(smtp_user, smtp_password)  # SMTPサーバーの認証
    server.sendmail(sender, [recipient], msg.as_string())  # メールの送信
    print('メールの送信に成功しました。')
finally:
    server.quit()  # SMTPサーバーからのログアウト

これを実行すると、先ほど同様に/new配下にきちんとメールが作成されていました!

恐らくコード側の問題で、エンコードされているっぽく読めたものではなかったですが、少なくとも送信はできていたので今回はこれで良しとしようと思います!!

まとめ

メールサーバの設定自体は、めちゃくちゃわかりやすいサイトがあったため、設定事項は多いが手順さえ守れば問題なく設定ができるものであった。

プライベートDNSを利用したメール配信も比較的簡単に実装できたので良かった。

今後は、VPCにローカルのパソコンから直接利用する方法がないか試してみようかなと思った。

3
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?