§2024-04-28
If you want Postfix to relay emails through both 210.242.152.235 and 114.39.29.69, you can specify multiple relay hosts by separating them with commas. Here's how you can modify the relayhost parameter to achieve this, /etc/postfix/main.cf
- in main.cf,
relayhost = [210.242.152.235],[114.39.29.69]
# relay_domains
relay_domains = gmail.com, mac.com, hotmail.com, yahoo.com.tw
Trying 59.126.118.193...
Connected to h2jammy.yushei.net.
Escape character is '^]'.
220 h2Jammy.yushei.net ESMTP Postfix (Ubuntu)
EHLO yushei.net
250-h2Jammy.yushei.net
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-STARTTLS
250-ENHANCEDSTATUSCODES
250-8BITMIME
250-DSN
250-SMTPUTF8
250 CHUNKING
MAIL FROM: alexlai@h2jammy.yushei.net
250 2.1.0 Ok
RCPT TO: rai.sousuke@gmail.com
250 2.1.5 Ok
RCPT TO: rai.sousuke@mac.com
250 2.1.5 Ok
RCPT TO: jinwinlin@hotmail.com
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
Subjct: test SMTP from orgpi16g to h2jammy
time is 2024-04-28 10:50
Tesing relayhosts, relay_domains
Hi
Bye
.
250 2.0.0 Ok: queued as 0CDCF40251705
quit
221 2.0.0 Bye
Connection closed by foreign host.
- erroro
Mail Delivery System
MAILER-DAEMON@h2jammy.yushei.net
10:50
This is the mail system at host http://h2jammy.yushei.net.
I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.
For further assistance, please send mail to postmaster.
If you do so, please include this problem report. You can
delete your own text from the attached returned message.
The mail system
<rai.sousuke@gmail.com>: host http://210.242.152.235[http://210.242.152.235] said: 554 5.7.1
<rai.sousuke@gmail.com>: Relay access denied (in reply to RCPT TO command)
<jinwinlin@hotmail.com>: host http://210.242.152.235[http://210.242.152.235] said: 554 5.7.1
<jinwinlin@hotmail.com>: Relay access denied (in reply to RCPT TO command)
<rai.sousuke@mac.com>: host http://210.242.152.235[http://210.242.152.235] said: 554 5.7.1
<rai.sousuke@mac.com>: Relay access denied (in reply to RCPT TO command)
How to set up postfix to accept and relay mail,
- traffice is from ip 210.242.152.235, 114.39.29.69
- and RCPT TO these domains, gmail.com, mac.com, hotmail.com, yahoo.com.tw
put the foolowing lines at the end of /etc/postfix/main.cf
# Set the network(s) that are allowed to send mail through this server
mynetworks = 127.0.0.0/8, 210.242.152.235, 114.39.29.69
# Define the domains for which relay is allowed
relay_domains = gmail.com, mac.com, hotmail.com, yahoo.com.tw
# Restricting relay access to specific IP addresses
smtpd_relay_restrictions = permit_mynetworks, reject_unauth_destination
Apr 28 13:12:47 h2Jammy postfix/smtp[21874]: warning: /etc/postfix/main.cf, line 60: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.0.0/16 Apr 28 13:12:47 h2Jammy postfix/smtp[21874]: warning: /etc/postfix/main.cf, line 66: overriding earlier entry: smtpd_relay_restrictions=permit_mynetworks permit_sasl_authenticated defer_unauth_destination Apr 28 13:12:48 h2Jammy postfix/bounce[21875]: warning: /etc/postfix/main.cf, line 60: overriding earlier entry: mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 192.168.0.0/16 Apr 28 13:12:48 h2Jammy postfix/bounce[21875]: warning: /etc/postfix/main.cf, line 66: overriding earlier entry: smtpd_relay_restrictions=permit_mynetworks permit_sasl_authenticated defer_unauth_destination
- sent mail to gmail.com, mac.com, hotmail.com
- mac.com, a迷惑nd hotmail.com will put mail into 迷惑baox
- gmail will reject with
Mail Delivery System MAILER-DAEMON@h2jammy.yushei.net 11:40 This is the mail system at host http://h2jammy.yushei.net. I'm sorry to have to inform you that your message could not be delivered to one or more recipients. It's attached below. For further assistance, please send mail to postmaster. If you do so, please include this problem report. You can delete your own text from the attached returned message. The mail system <rai.sousuke@gmail.com>: host http://gmail-smtp-in.l.google.com[http://64.233.187.27] said: 550-5.7.1 [http://59.126.118.194] Messages missing a valid Message-ID header are not 550-5.7.1 accepted. For more information, go to 550-5.7.1 https://support.google.com/mail/?p=RfcMessageNonCompliant and review 550 5.7.1 RFC 5322 specifications. z8-20020a656108000000b005d8b8c6a98bsi17908712pgu.588 - gsmtp (in reply to end of DATA command)
- Answer by chatGpt
When using Telnet to manually send an email, you'll need to include the necessary headers, including the Message-ID header, yourself. Here's a basic example of how you can construct an email with Telnet and include the Message-ID header:
telnet smtp.gmail.com 25
EHLO yushei.net
MAIL FROM:<alexlai@h2jammy.yushei.net>
RCPT TO:<rai.sousuke@gmail.com>
RCPT TO:<rai.sousuke@mac.com>
RCPT TO:<jinwinlin@hotmail.com>
RCPT TO: <alexlai@h2jammy.yushei.net>
DATA
From: <alexlai@h2jammy.yushei.net>
To: <rai.sousuke@gmail.com>
Subject: testing h2jammy.yushei.net relay
Message-ID: <9e896d72-6c42-43dc-b8fb-4e0ca1806009@h2jammy.yushei.net>
Date: Tue, 28 Apr 2024 15:3800 +0000
Content-Type: text/plain; charset=utf-8
Testing h2jammy.yushei.net postfix
.
QUIT
In this example:
Replace your.email@gmail.com with your Gmail email address. Replace rai.sousuke@gmail.com with the recipient's email address. Replace Your Name, Receiver Name, Your Subject, and the body of the email with your desired content. Ensure that unique_message_id@example.com is replaced with a unique identifier following the format specified in RFC 5322. For example, you can generate a UUID and append it with @example.com. Make sure to follow the SMTP protocol's rules and formatting requirements, such as ending each line with CRLF (\r\n) and including a single period (.) on a line by itself to indicate the end of the message body.
After connecting to the SMTP server using Telnet and providing the necessary commands, you should be able to send the email with the Message-ID header included.
User How to generate it ChatGPT To generate a unique Message-ID header, you typically follow the format specified in RFC 5322. Here's how you can generate a simple Message-ID using Python:
python Copy code import uuid
def generate_message_id(): hostname = "example.com" # Replace with your domain name unique_id = str(uuid.uuid4()) message_id = "<" + unique_id + "@" + hostname + ">" return message_id
print(generate_message_id()) This Python script utilizes the uuid module to generate a UUID (Universally Unique Identifier) and then constructs a Message-ID string using the format uuid@example.com. You can replace "example.com" with your actual domain name.
Each time you call the generate_message_id() function, it will produce a unique Message-ID string.
You can incorporate this function into your Telnet session to generate a Message-ID header for your email.
```python
import uuid
def generate_message_id():
hostname = "example.com" # Replace with your domain name
unique_id = str(uuid.uuid4())
message_id = "<" + unique_id + "@" + hostname + ">"
return message_id
print(generate_message_id())
===
Apr 28 13:25:55 h2Jammy postfix/cleanup[22286]: 141F340251705: message-id=<9e896d72-6c42-43dc-b8fb-4e0ca1806009@h2jammy.yushei.net>
Apr 28 13:25:55 h2Jammy opendkim[897]: 141F340251705: can't determine message sender; accepting
Apr 28 13:25:55 h2Jammy postfix/qmgr[20974]: 141F340251705: from=<alexlai@h2jammy.yushei.net>, size=484, nrcpt=1 (queue active)
Apr 28 13:25:56 h2Jammy postfix/relay/smtp[22318]: connect to gmail-smtp-in.l.google.com[2404:6800:4008:c01::1a]:25: Network is unreachable
Apr 28 13:25:57 h2Jammy postfix/relay/smtp[22318]: 141F340251705: to=<rai.sousuke@gmail.com>, relay=gmail-smtp-in.l.google.com[64.233.187.27]:25, delay=70, delays=69/0.02/0.68/0.45, dsn=5.7.1, status=bounced (host gmail-smtp-in.l.google.com[64.233.187.27] said: 550-5.7.1 [59.126.118.194] Gmail has detected that this message is not RFC 5322 550-5.7.1 compliant: 550-5.7.1 'From' header is missing. 550-5.7.1 To reduce the amount of spam sent to Gmail, this message has been 550-5.7.1 blocked. For more information, go to 550-5.7.1 https://support.google.com/mail/?p=RfcMessageNonCompliant and review 550 5.7.1 RFC 5322 specifications. k129-20020a633d87000000b005e83b6752bdsi15496315pga.269 - gsmtp (in reply to end of DATA command))
Apr 28 13:25:57 h2Jammy postfix/cleanup[22286]: 1DA7D4025170F: message-id=<20240428052557.1DA7D4025170F@h2Jammy.yushei.net>
Apr 28 13:25:57 h2Jammy postfix/bounce[22319]: 141F340251705: sender non-delivery notification: 1DA7D4025170F
Apr 28 13:25:57 h2Jammy postfix/qmgr[20974]: 1DA7D4025170F: from=<>, size=3539, nrcpt=1 (queue active)
Apr 28 13:25:57 h2Jammy postfix/qmgr[20974]: 141F340251705: removed
Apr 28 13:25:57 h2Jammy postfix/local[22320]: 1DA7D4025170F: to=<alexlai@h2jammy.yushei.net>, relay=local, delay=0.01, delays=0/0.01/0/0, dsn=2.0.0, status=sent (delivered to maildir)
Apr 28 13:25:57 h2Jammy postfix/qmgr[20974]: 1DA7D4025170F: removed
Apr 28 13:25:57 h2Jammy postfix/smtpd[22267]: disconnect from 210-242-152-235.hinet-ip.hinet.net[210.242.152.235] ehlo=1 mail=1 rcpt=1 data=1 quit=1 commands=5
Apr 28 13:25:59 h2Jammy dovecot: imap-login: Login: user=<alexlai>, method=PLAIN, rip=114.33.29.69, lip=192.168.16.248, mpid=22322, session=<yk1BXyEXcNVyIR1F>
Apr 28 13:26:00 h2Jammy dovecot: imap-login: Login: user=<alexlai>, method=PLAIN, rip=114.33.29.69, lip=192.168.16.248, mpid=22324, session=<yWFEXyEXgNVyIR1F>
Apr 28 13:26:00 h2Jammy dovecot: imap(alexlai)<22324><yWFEXyEXgNVyIR1F>: Disconnected: Logged out in=104 out=1030 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
Apr 28 13:26:00 h2Jammy dovecot: imap-login: Login: user=<alexlai>, method=PLAIN, rip=114.33.29.69, lip=192.168.16.248, mpid=22326, session=<appGXyEXjtVyIR1F>
Apr 28 13:26:00 h2Jammy dovecot: imap(alexlai)<22326><appGXyEXjtVyIR1F>: Disconnected: Logged out in=104 out=967 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
Apr 28 13:26:00 h2Jammy dovecot: imap(alexlai)<22322><yk1BXyEXcNVyIR1F>: Disconnected: Logged out in=415 out=4417 deleted=0 expunged=0 trashed=0 hdr_count=3 hdr_bytes=1965 body_count=0 body_bytes=0
Apr 28 13:26:00 h2Jammy dovecot: imap-login: Login: user=<alexlai>, method=PLAIN, rip=114.33.29.69, lip=192.168.16.248, mpid=22328, session=<yrNJXyEXmNVyIR1F>
Apr 28 13:26:00 h2Jammy dovecot: imap(alexlai)<22328><yrNJXyEXmNVyIR1F>: Disconnected: Logged out in=87 out=661 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
Apr 28 13:26:00 h2Jammy dovecot: imap-login: Login: user=<alexlai>, method=PLAIN, rip=114.33.29.69, lip=192.168.16.248, mpid=22330, session=<ketLXyEXntVyIR1F>
Apr 28 13:26:00 h2Jammy dovecot: imap(alexlai)<22330><ketLXyEXntVyIR1F>: Disconnected: Logged out in=170 out=3434 deleted=0 expunged=0 trashed=0 hdr_count=1 hdr_bytes=655 body_count=2 body_bytes=1097
Apr 28 13:26:00 h2Jammy dovecot: imap-login: Login: user=<alexlai>, method=PLAIN, rip=114.33.29.69, lip=192.168.16.248, mpid=22332, session=<MqJSXyEXrtVyIR1F>
Apr 28 13:26:01 h2Jammy dovecot: imap(alexlai)<22332><MqJSXyEXrtVyIR1F>: Disconnected: Logged out in=494 out=3826 deleted=0 expunged=0 trashed=0 hdr_count=2 hdr_bytes=1310 body_count=0 body_bytes=0
Apr 28 13:26:01 h2Jammy dovecot: imap-login: Login: user=<alexlai>, method=PLAIN, rip=114.33.29.69, lip=192.168.16.248, mpid=22334, session=<oulVXyEXvtVyIR1F>
Apr 28 13:26:01 h2Jammy dovecot: imap(alexlai)<22334><oulVXyEXvtVyIR1F>: Disconnected: Logged out in=87 out=661 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0
Apr 28 13:26:01 h2Jammy dovecot: imap-login: Login: user=<alexlai>, method=PLAIN, rip=114.33.29.69, lip=192.168.16.248, mpid=22336, session=<Sg5cXyEXzNVyIR1F>
Apr 28 13:26:01 h2Jammy dovecot: imap(alexlai)<22336><Sg5cXyEXzNVyIR1F>: Disconnected: Logged out in=388 out=3218 deleted=0 expunged=0 trashed=0 hdr_count=2 hdr_bytes=1310 body_count=0 body_bytes=0
Apr 28 13:26:01 h2Jammy dovecot: imap-login: Login: user=<alexlai>, method=PLAIN, rip=114.33.29.69, lip=192.168.16.248, mpid=22338, session=<gTlfXyEXztVyIR1F>
Apr 28 13:26:01 h2Jammy dovecot: imap(alexlai)<22338><gTlfXyEXztVyIR1F>: Disconnected: Logged out in=87 out=661 deleted=0 expunged=0 trashed=0 hdr_count=0 hdr_bytes=0 body_count=0 body_bytes=0