Smtp

設置 exim4 以從 Web 應用程序發送郵件

  • September 3, 2019

我想設置自己的 SMTP 伺服器(僅發送郵件)來處理來自我的 Web 應用程序的所有通知郵件等

dpkg-reconfigure exim4-config

Type:                   internet site
FQDN:                   smtp.mydomain.com
SMTP listener:          127.0.0.1; ::1
Mail destinations:      Debian-Buster10; localhost
Relay:                  (empty)
Follow up screen relay: (empty)
DNS queries minimal:    No
Delivery method:        Maildir in home dir
Split conf files:       No

我通過 PHPmailer 發送郵件。它已發送但從未收到?

phpmailer

try{
   $mail = new PHPMailer(true);
   $mail->SMTPDebug    = 1;
   $mail->SMTPSecure   = 'tls';
   $mail->SMTPAutoTLS  = false;
   $mail->SMTPAuth     = true;
   $mail->SMTPOptions  = [
       'ssl' => [
           'verify_peer'       => false,
           'verify_peer_name'  => false,
           'allow_self_signed' => true
       ]
   ];
   //$mail->CharSet        = 'UTF-8';
   $mail->IsSMTP();

   $mail->Port     = 25;
   $mail->Host     = '127.0.0.1';
   $mail->Username = 'user';
   $mail->Password = 'pass';

   $mail->AddAddress('me@domain.com', 'me');
   $mail->From         = 'me@domain.com';
   $mail->FromName     = 'me';
   $mail->Subject = 'test mail';
   $mail->Body = 'hello world';
   $mail->Send();
}
catch(phpmailerException $e){
   echo "err: ".$e->getMessage()."\n";
}

phpmailer SMTP 調試輸出

2019-09-03 06:59:35 CLIENT -> SERVER: EHLO Test-Athlon-3700-2gb
2019-09-03 06:59:35 CLIENT -> SERVER: STARTTLS
2019-09-03 06:59:35 CLIENT -> SERVER: EHLO Test-Athlon-3700-2gb
2019-09-03 06:59:35 CLIENT -> SERVER: AUTH PLAIN
2019-09-03 06:59:35 CLIENT -> SERVER: AGR5bmFjY291bnQAVWF4ZDIwMDEr
2019-09-03 06:59:35 CLIENT -> SERVER: MAIL FROM:<xxx@xxx.xx>
2019-09-03 06:59:35 CLIENT -> SERVER: RCPT TO:<xxx@gmail.com>
2019-09-03 06:59:35 CLIENT -> SERVER: DATA
2019-09-03 06:59:35 CLIENT -> SERVER: Date: Tue, 3 Sep 2019 06:59:35 +0000
2019-09-03 06:59:35 CLIENT -> SERVER: To: me <xxx@gmail.com>
2019-09-03 06:59:35 CLIENT -> SERVER: From: me <xxx@xxx.xx>
2019-09-03 06:59:35 CLIENT -> SERVER: Subject: test mail
2019-09-03 06:59:35 CLIENT -> SERVER: Message-ID: <6ade75e609c3a3e595f324172e0d08eb@Test-Athlon-3700-2gb>
2019-09-03 06:59:35 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.14 (https://github.com/PHPMailer/PHPMailer)
2019-09-03 06:59:35 CLIENT -> SERVER: MIME-Version: 1.0
2019-09-03 06:59:35 CLIENT -> SERVER: Content-Type: text/plain; charset=iso-8859-1
2019-09-03 06:59:35 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
2019-09-03 06:59:35 CLIENT -> SERVER:
2019-09-03 06:59:35 CLIENT -> SERVER: hello world
2019-09-03 06:59:35 CLIENT -> SERVER:
2019-09-03 06:59:35 CLIENT -> SERVER: .
2019-09-03 06:59:36 CLIENT -> SERVER: QUIT

您可能沒有在 Exim 中啟用身份驗證(它已被禁用),但您在 phpmailer 中需要它。

從 phpmailer 中刪除對 TLS 和身份驗證的要求。

引用自:https://unix.stackexchange.com/questions/538792