最後更新: 2024-02-16
目錄
imap
# Login:
1 login user_name password
1 OK [CAPABILITY IMAP4rev1 LITERAL+ SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS MULTIAPPEND UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS QUOTA ACL RIGHTS=texk] Logged in
# Logout:
. logout
# 查看有什麼 Folder:
2 list "" "*"
* LIST (\HasNoChildren) "." "Trash"
* LIST (\HasNoChildren) "." "Junk"
* LIST (\HasNoChildren) "." "Sent"
* LIST (\HasNoChildren) "." "Drafts"
* LIST (\HasNoChildren) "." "INBOX"
2 OK List completed.
# 查看某 Folder 內的 sub-folder:
3 list "backup" "*"
* LIST (\HasChildren) "/" "backup"
* LIST (\HasNoChildren) "/" "backup/F2"
* LIST (\HasNoChildren) "/" "backup/F1"
3 OK List completed.
# 查看某 Folder 資訊:
4 status INBOX (messages)
* STATUS "INBOX" (MESSAGES 1) 4 OK Status completed.
. status INBOX (unseen)
# 建立,刪除,rename Folder:
. create INBOX.test3
. delete INBOX.test3
. rename INBOX.test1 INBOX.test3
# 進入某 Folder:
. select INBOX.test2
# Subscribe:
. lsub "" "*"
. subscribe INBOX.test3
. OK Completed
. unsubscribe INBOX.test3
. OK Completed
# Finding messages
. SEARCH FROM "[email protected]" BEFORE 1-Nov-2009
. SEARCH FROM "[email protected]" SINCE 4-May-2017
# TO "<mailaddress>"
# SUBJECT <string>
# BODY <string>
# Fetching messages
BODY[TEXT] # Just the mail body, without the headers
BODY[HEADER] # The mail headers
FLAGS # Flags set for the message
UID # The UID of the message (N)
. FETCH 817 FLAGS
* 817 FETCH (FLAGS (\Answered \Deleted \Seen))
# Set flag
a STORE 22 +FLAGS \Deleted set as deleted email 22 (twenty-second email)
a STORE 22 -FLAGS \Deleted restore, undelete ... email n. 22 in mailbox
# Bulk set flag
a STORE 1:* +FLAGS \Seen set read all emails
a STORE 1:* -FLAGS \Seen set unread all emails
a STORE 10:100 +FLAGS \Seen set as read emails from 10 to 100(sequence number range)
* 所有數字都可以用 "." 代替
其他:
. capability
. getquotaroot inbox
. getacl inbox
Remark:
IMAP has no built in move command, when you move a message you actually copy it to another folder and then delete the original.
imap 成功 login 後不會 move new/ 內的 file 到 cur/
POP3
USER userid
+OK
PASS password
+OK Logged in.
STAT
# Returns total number of messages and total size
+OK 4 1196
LIST
# Lists all messages: Returns indexed list of messages, along with size
+OK 4 messages: 1 299 2 299 3 299 4 299 .
RETR N
Return-Path: <s@a> X-Original-To: r@b Delivered-To: r@b Received: from FromServer (x.ctinets.com [x.x.x.x]) by server (Postfix) with SMTP id 9765D40D73DE for <r@b>; Wed, 26 Oct 2016 10:43:48 +0800 (HKT) test msg .
DELE N
+OK Marked to be deleted.
RSET
resets any messages previously marked for deletion in this session so that the QUIT command will not delete them.
TOP
Retrieving part of the message
# Return headers only:
TOP 1 0
# Return headers and first 10 lines of body:
TOP 1 10
QUIT
+OK Logging out, messages deleted.
ID 與 mail 的對應:
uidl
+OK 1 00000001581017bb 2 00000002581017bb 3 00000003581017bb 4 00000004581017bb
Remark
pop3 成功 login 後, 所有在 new/ 內的 file (不論是否 mail) 都會移到 cur/
smtp test login
# gen login name
perl -MMIME::Base64 -e 'print encode_base64("datahunter\@datahunter.org");'
# gen password
perl -MMIME::Base64 -e 'print encode_base64("password");'
測試:
telnet <mail_server> 25
# EHLO 在 postfix 上是沒有 log 的
C: EHLO mailserver.com
C: AUTH LOGIN
S: 334 VXNlcm5hbWU6;
C: <早前 gen 的 login name>
S: Now the server should have returned 334 UGFzc3dvcmQ6;
C: <早前gen password>
# login 成功了後都是沒有 log 的
S: 235 2.7.0 Authentication successful
# login fail 才有 log 內有 "warning: unknown[192.168.123.200]: SASL LOGIN authentication failed: UGFzc3dvcmQ6"
# 成功的 log 要交了 "mail from:" 及 "rcpt to:" 後才出
0311F3019: client=unknown[x.x.x.x], sasl_method=LOGIN, [email protected]
進階
Mail Body
Message-ID: <1> Date: Fri, 23 Feb 2024 14:48:28 +0800 To: a@a From: b@b Subject: test test msg
沒有 Message-ID 及 Date 很易被當成 SPAM
其他 mail header
Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit