如何使用 Postfix 发送电子邮件到本地主机?

如何使用 Postfix 发送电子邮件到本地主机?

仅收到一封电子邮件:

Return-Path: <[email protected]>
X-Original-To: [email protected]
Delivered-To: [email protected]
Received: from mordor.saundersconsulting.tech (localhost [127.0.0.1])
    by mordor.saundersconsulting.tech (Postfix) with ESMTP id 767671BD6
    for <[email protected]>; Sat, 16 Dec 2023 11:57:53 -0800 (PST)
Date: Sat, 16 Dec 2023 11:57:53 -0800
To: [email protected]
From: [email protected]
Subject: test Sat, 16 Dec 2023 11:57:53 -0800
Message-Id: <[email protected]>
X-Mailer: swaks v20201014.0 jetmore.org/john/code/swaks/

This is a test mailing

发送了两个:

nicholas@mordor:~$ 
nicholas@mordor:~$ swaks --to [email protected] --server localhost
=== Trying localhost:25...
=== Connected to localhost.
<-  220 mordor.saundersconsulting.tech ESMTP Postfix (Ubuntu)
 -> EHLO mordor.saundersconsulting.tech
<-  250-mordor.saundersconsulting.tech
<-  250-PIPELINING
<-  250-SIZE 10240000
<-  250-VRFY
<-  250-ETRN
<-  250-STARTTLS
<-  250-ENHANCEDSTATUSCODES
<-  250-8BITMIME
<-  250-DSN
<-  250-SMTPUTF8
<-  250 CHUNKING
 -> MAIL FROM:<[email protected]>
<-  250 2.1.0 Ok
 -> RCPT TO:<[email protected]>
<-  250 2.1.5 Ok
 -> DATA
<-  354 End data with <CR><LF>.<CR><LF>
 -> Date: Sat, 16 Dec 2023 11:57:53 -0800
 -> To: [email protected]
 -> From: [email protected]
 -> Subject: test Sat, 16 Dec 2023 11:57:53 -0800
 -> Message-Id: <[email protected]>
 -> X-Mailer: swaks v20201014.0 jetmore.org/john/code/swaks/
 -> 
 -> This is a test mailing
 -> 
 -> 
 -> .
<-  250 2.0.0 Ok: queued as 767671BD6
 -> QUIT
<-  221 2.0.0 Bye
=== Connection closed with remote host.
nicholas@mordor:~$ 
nicholas@mordor:~$ swaks --to nick@localhost --server localhost
=== Trying localhost:25...
=== Connected to localhost.
<-  220 mordor.saundersconsulting.tech ESMTP Postfix (Ubuntu)
 -> EHLO mordor.saundersconsulting.tech
<-  250-mordor.saundersconsulting.tech
<-  250-PIPELINING
<-  250-SIZE 10240000
<-  250-VRFY
<-  250-ETRN
<-  250-STARTTLS
<-  250-ENHANCEDSTATUSCODES
<-  250-8BITMIME
<-  250-DSN
<-  250-SMTPUTF8
<-  250 CHUNKING
 -> MAIL FROM:<[email protected]>
<-  250 2.1.0 Ok
 -> RCPT TO:<nick@localhost>
<-  250 2.1.5 Ok
 -> DATA
<-  354 End data with <CR><LF>.<CR><LF>
 -> Date: Sat, 16 Dec 2023 11:58:02 -0800
 -> To: nick@localhost
 -> From: [email protected]
 -> Subject: test Sat, 16 Dec 2023 11:58:02 -0800
 -> Message-Id: <[email protected]>
 -> X-Mailer: swaks v20201014.0 jetmore.org/john/code/swaks/
 -> 
 -> This is a test mailing
 -> 
 -> 
 -> .
<-  250 2.0.0 Ok: queued as F2CA81BD8
 -> QUIT
<-  221 2.0.0 Bye
=== Connection closed with remote host.
nicholas@mordor:~$ 
nicholas@mordor:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04 LTS
Release:    22.04
Codename:   jammy
nicholas@mordor:~$ 

本地主机电子邮件无法发送。我正在使用Postfix并希望在本地主机上发送。

nicholas@mordor:~$ 
nicholas@mordor:~$ sudo postconf | grep mordor
postconf: warning: /etc/postfix/main.cf, line 60: overriding earlier entry: myorigin=/etc/mailname
postconf: warning: /etc/postfix/main.cf, line 62: overriding earlier entry: mydestination=$myhostname, mordor.saundersconsulting.tech, localhost.saundersconsulting.tech, , localhost
mydestination = mordor.saundersconsulting.tech
myhostname = mordor.saundersconsulting.tech
myorigin = mordor.saundersconsulting.tech
nicholas@mordor:~$ 
nicholas@mordor:~$ hostname -f
mordor.saundersconsulting.tech
nicholas@mordor:~$ 

日志显示:

Dec 16 12:25:46 mordor fetchmail[1466399]: syslog and logfile options are both set, ignoring syslog, and logging to /var/log/fetchmail.log
Dec 16 12:33:31 mordor postfix/postfix-script[1478100]: starting the Postfix mail system
Dec 16 12:33:31 mordor postfix/master[1478102]: daemon started -- version 3.6.4, configuration /etc/postfix
Dec 16 12:35:47 mordor postfix/smtpd[1481569]: connect from localhost[127.0.0.1]
Dec 16 12:35:47 mordor postfix/smtpd[1481569]: NOQUEUE: reject: RCPT from localhost[127.0.0.1]: 550 5.1.1 <local_user@localhost>: Recipient address rejected: User unknown in local recipient table; from=<[email protected]> to=<local_user@localhost> proto=ESMTP helo=<imap.gmail.com>
Dec 16 12:35:47 mordor postfix/smtpd[1481573]: connect from localhost[127.0.0.1]
Dec 16 12:35:47 mordor postfix/smtpd[1481573]: 2246C2182: client=localhost[127.0.0.1]
Dec 16 12:35:47 mordor postfix/cleanup[1481574]: 2246C2182: message-id=<[email protected]>
Dec 16 12:35:47 mordor postfix/smtpd[1481573]: disconnect from localhost[127.0.0.1] helo=1 mail=1 rcpt=1 data=1 quit=1 commands=5
Dec 16 12:35:47 mordor postfix/qmgr[1478104]: 2246C2182: from=<>, size=2244, nrcpt=1 (queue active)
Dec 16 12:35:47 mordor postfix/smtpd[1481569]: NOQUEUE: reject: RCPT from localhost[127.0.0.1]: 550 5.1.1 <administrator@localhost>: Recipient address rejected: User unknown in local recipient table; from=<[email protected]> to=<administrator@localhost> proto=ESMTP helo=<imap.gmail.com>
Dec 16 12:35:47 mordor postfix/smtpd[1481569]: disconnect from localhost[127.0.0.1] ehlo=1 mail=1 rcpt=0/2 rset=1 quit=1 commands=4/6
Dec 16 12:35:47 mordor postfix/smtpd[1481573]: connect from localhost[127.0.0.1]
Dec 16 12:35:47 mordor postfix/smtpd[1481573]: NOQUEUE: reject: RCPT from localhost[127.0.0.1]: 550 5.1.1 <local_user@localhost>: Recipient address rejected: User unknown in local recipient table; from=<[email protected]> to=<local_user@localhost> proto=ESMTP helo=<imap.gmail.com>
Dec 16 12:35:47 mordor postfix/smtpd[1481569]: connect from localhost[127.0.0.1]
Dec 16 12:35:47 mordor postfix/smtpd[1481569]: 7DC2E2184: client=localhost[127.0.0.1]
Dec 16 12:35:47 mordor postfix/cleanup[1481574]: 7DC2E2184: message-id=<[email protected]>
Dec 16 12:35:47 mordor postfix/smtpd[1481569]: disconnect from localhost[127.0.0.1] helo=1 mail=1 rcpt=1 data=1 quit=1 commands=5
Dec 16 12:35:47 mordor postfix/qmgr[1478104]: 7DC2E2184: from=<>, size=2244, nrcpt=1 (queue active)
Dec 16 12:35:47 mordor postfix/smtpd[1481573]: NOQUEUE: reject: RCPT from localhost[127.0.0.1]: 550 5.1.1 <administrator@localhost>: Recipient address rejected: User unknown in local recipient table; from=<[email protected]> to=<administrator@localhost> proto=ESMTP helo=<imap.gmail.com>
Dec 16 12:35:47 mordor postfix/smtpd[1481573]: disconnect from localhost[127.0.0.1] ehlo=1 mail=1 rcpt=0/2 rset=1 quit=1 commands=4/6
Dec 16 12:35:57 mordor postfix/smtp[1481575]: 2246C2182: to=<[email protected]>, relay=none, delay=10, delays=0.07/0.01/10/0, dsn=4.4.3, status=deferred (Host or domain name not found. Name service error for name=gmail.com type=MX: Host not found, try again)
Dec 16 12:35:57 mordor postfix/smtp[1481576]: 7DC2E2184: to=<[email protected]>, relay=none, delay=10, delays=0.06/0.01/10/0, dsn=4.4.3, status=deferred (Host or domain name not found. Name service error for name=gmail.com type=MX: Host not found, try again)

答案1

我不太确定解决方案是什么:

nicholas@mordor:~$ 
nicholas@mordor:~$ postconf | grep mordor
mydestination = $myhostname, mordor.saundersconsulting.tech, localhost
myhostname = mordor.saundersconsulting.tech
myorigin = mordor.saundersconsulting.tech
nicholas@mordor:~$ 
nicholas@mordor:~$ postconf | grep host
address_verify_relayhost = $relayhost
address_verify_sender_dependent_relayhost_maps = $sender_dependent_relayhost_maps
empty_address_relayhost_maps_lookup_key = <>
invalid_hostname_reject_code = 501
lmtp_host_lookup = dns
lmtp_lhlo_name = $myhostname
lmtp_tls_force_insecure_host_tlsa_lookup = no
lmtp_tls_verify_cert_match = hostname
local_transport = local:$myhostname
milter_macro_daemon_name = $myhostname
milter_mail_macros = i {auth_type} {auth_authen} {auth_author} {mail_addr} {mail_host} {mail_mailer}
milter_rcpt_macros = i {rcpt_addr} {rcpt_host} {rcpt_mailer}
mydestination = $myhostname, mordor.saundersconsulting.tech, localhost
myhostname = mordor.saundersconsulting.tech
mynetworks_style = ${{$compatibility_level} <level {2} ? {subnet} : {host}}
proxy_read_maps = $local_recipient_maps $mydestination $virtual_alias_maps $virtual_alias_domains $virtual_mailbox_maps $virtual_mailbox_domains $relay_recipient_maps $relay_domains $canonical_maps $sender_canonical_maps $recipient_canonical_maps $relocated_maps $transport_maps $mynetworks $smtpd_sender_login_maps $sender_bcc_maps $recipient_bcc_maps $smtp_generic_maps $lmtp_generic_maps $alias_maps $smtpd_client_restrictions $smtpd_helo_restrictions $smtpd_sender_restrictions $smtpd_relay_restrictions $smtpd_recipient_restrictions $address_verify_sender_dependent_default_transport_maps $address_verify_sender_dependent_relayhost_maps $address_verify_transport_maps $fallback_transport_maps $lmtp_discard_lhlo_keyword_address_maps $lmtp_pix_workaround_maps $lmtp_sasl_password_maps $lmtp_tls_policy_maps $mailbox_command_maps $mailbox_transport_maps $postscreen_discard_ehlo_keyword_address_maps $rbl_reply_maps $sender_dependent_default_transport_maps $sender_dependent_relayhost_maps $smtp_discard_ehlo_keyword_address_maps $smtp_pix_workaround_maps $smtp_sasl_password_maps $smtp_tls_policy_maps $smtpd_discard_ehlo_keyword_address_maps $smtpd_milter_maps $virtual_gid_maps $virtual_uid_maps $local_login_sender_maps $postscreen_reject_footer_maps $smtpd_reject_footer_maps $tls_server_sni_maps
relayhost = $mydomain
sender_dependent_relayhost_maps =
smtp_helo_name = $myhostname
smtp_host_lookup = dns
smtp_tls_force_insecure_host_tlsa_lookup = no
smtp_tls_verify_cert_match = hostname
smtpd_authorized_xclient_hosts =
smtpd_authorized_xforward_hosts =
smtpd_banner = $myhostname ESMTP $mail_name (Ubuntu)
smtpd_proxy_ehlo = $myhostname
unknown_helo_hostname_tempfail_action = $reject_tempfail_action
unknown_hostname_reject_code = 450
nicholas@mordor:~$ 

但这似乎符合我的目的,即向我自己发送和接收 foo@localhost 或 foo@fqdn

相关内容