私のサーバーはSSL暗号化を使用して電子メールを送信しますか?

私のサーバーはSSL暗号化を使用して電子メールを送信しますか?

を使用して小さなメールサーバーを展開しましたsendmail。暗号化の有無にかかわらず、配信要求を受け入れるようにプロキシが正しく設定されていると思います。その理由は、次の Telnet セッションを介して行われるためです。

usr@host:~$ nc -Cw 60 localhost 25
220 mail.mydomain.com ESMTP Sendmail 8.15.2/8.15.2/Debian-14~deb10u1; Tue, 8 Dec 2020 19:24:30 GMT; (No UCE/UBE) logging access from: localhost(OK)-localhost [127.0.0.1]
EHLO localhost
250-mail.mydomain.com Hello localhost [127.0.0.1], pleased to meet you
250-ENHANCEDSTATUSCODES
250-PIPELINING
250-EXPN
250-VERB
250-8BITMIME
250-SIZE
250-DSN
250-ETRN
250-AUTH DIGEST-MD5 CRAM-MD5
250-STARTTLS
250-DELIVERBY
250 HELP
MAIL FROM: [email protected]
250 2.1.0 [email protected]... Sender ok
RCPT TO: [email protected]
250 2.1.5 [email protected]... Recipient ok
DATA
354 Enter mail, end with "." on a line by itself
From: [email protected]
To: [email protected]
Subject: Sendmail test

This is a test mail delivered with Sendmail.
.
250 2.0.0 0B8JOUMo005314 Message accepted for delivery
QUIT
221 2.0.0 mail.mydomain.com closing connection

..そしてPythonコードスニペット:

def send_mail_ssl(subject, text, receiver, sender):
  body = _BODY_PATTERN.format(sender=sender,
                              receiver=receiver,
                              subject=subject,
                              text=text)
  context = ssl.create_default_context()
  with smtplib.SMTP_SSL('mail.mydomain.com', 465, context=context) as server:
    server.sendmail(sender, receiver, body)

def send_mail_tls(subject, text, receiver, sender):
  body = _BODY_PATTERN.format(sender=sender,
                              receiver=receiver,
                              subject=subject,
                              text=text)
  context = ssl.create_default_context()
  try:
    server = smtplib.SMTP('mail.mydomain.com', 25)
    server.ehlo()
    server.starttls(context=context)
    server.ehlo()
    server.sendmail(sender, receiver, body)
  except Exception as e:
    print(e)
  finally:
    server.quit()

...電子メールが成功裏に送信されました。ただし、電子メールを転送するためにターゲットSMTPノードと暗号化されたセッションが確立されているかどうかはわかりません。どうやって確認できますか?

12/09アップデート コメントに記載されているので、ここにテストメールに含まれるヘッダーのいくつかを追加します。

Received: from AM6EUR05HT200.eop-eur05.prod.protection.outlook.com
 (2603:10a6:3:e3::27) by HE1PR06MB3930.eurprd06.prod.outlook.com with HTTPS
 via HE1PR0502CA0017.EURPRD05.PROD.OUTLOOK.COM; Tue, 8 Dec 2020 17:43:15 +0000
Received: from AM6EUR05FT016.eop-eur05.prod.protection.outlook.com
 (2a01:111:e400:fc11::49) by
 AM6EUR05HT200.eop-eur05.prod.protection.outlook.com (2a01:111:e400:fc11::294)
 with Microsoft SMTP Server (version=TLS1_2,
 cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3632.17; Tue, 8 Dec
 2020 17:43:14 +0000
Authentication-Results: spf=pass (sender IP is MYSERVERIP)
 smtp.mailfrom=mail.mydomain.com; live.it; dkim=none (message not signed)
 header.d=none;live.it; dmarc=bestguesspass action=none
 header.from=mail.mydomain.com;compauth=pass reason=109
Received-SPF: Pass (protection.outlook.com: domain of mail.mydomain.com
 designates MYSERVERIP as permitted sender)
 receiver=protection.outlook.com; client-ip=MYSERVERIP;
 helo=mail.mydomain.com;
Received: from mail.mydomain.com (MYSERVERIP) by
 AM6EUR05FT016.mail.protection.outlook.com (10.233.240.243) with Microsoft
 SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id
 15.20.3632.17 via Frontend Transport; Tue, 8 Dec 2020 17:43:14 +0000
X-IncomingTopHeaderMarker:
 OriginalChecksum:A8C3955649979800BCCE5770882A4FE8994D8B0B90393756BB8AD24255EBB904;UpperCasedChecksum:DC234C8D58F32E07B6AFB42D6ABE9D17CF745F6968D869D01974CBC93315655A;SizeAsReceived:484;Count:6
Received: from mail.mydomain.com (mail.mydomain.com [MYSERVERIP])
    by mail.mydomain.com (8.15.2/8.15.2/Debian-14~deb10u1) with ESMTPS id 0B8HhDPU003097
    (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT)
    for <[email protected]>; Tue, 8 Dec 2020 17:43:14 GMT
[...]

ベストアンサー1

  1. 最初の試み - SMTPポートtcp / 25へのクラシック接続を使用してTelnetセッションを使用します。これは問題なく標準です。これを使用でき、EHLOの後にSTARTTLSを使用して暗号化されたセッションに切り替えることができます。しかし、あなたのPythonはSSLベースのSMTP、つまりSMTPSを使用するように設定されています。しばらく前に試しましたが、ほとんど放棄しました。 TCP/465 を使用し、最初から暗号化されます。いくつかの欠点があります。

  2. はい。 Pythonは電子メールを送信サーバーに送信するときに一種の暗号化を使用しています。ただし、送信サーバーから最終宛先サーバーに電子メールを送信することとは関係ありません(直接または他の中継を介して)。これは、関連サーバーとそのサーバーのアルゴリズムのリスト、デフォルト設定などによってネゴシエートされます。私が知る限り、SMTP MTA間の暗号化を強制する標準はありません。

おすすめ記事