SMTP Commands Reference
Referensi lengkap untuk perintah SMTP, kode respons, dan alur protokol email dengan contoh interaktif.
EHLOsessionEHLO <hostname>Extended greeting; identifies the client and requests ESMTP extensions.
EHLO mail.example.comHELOsessionHELO <hostname>Basic SMTP greeting. Use EHLO for modern servers.
HELO mail.example.comQUITsessionQUITClose the SMTP connection gracefully.
QUITSTARTTLSsessionSTARTTLSUpgrade the connection to TLS encryption.
STARTTLSNOOPsessionNOOPNo operation; used to keep the connection alive.
NOOPRSETsessionRSETAbort the current mail transaction and reset the session.
RSETAUTHauthAUTH <mechanism> [credentials]Authenticate the client to the server (PLAIN, LOGIN, CRAM-MD5).
AUTH LOGINMAIL FROMmessageMAIL FROM:<address>Specify the sender envelope address.
MAIL FROM:<sender@example.com>RCPT TOmessageRCPT TO:<address>Specify a recipient envelope address. Can be repeated.
RCPT TO:<recipient@example.com>DATAmessageDATABegin transmitting the message body. End with a line containing only a period.
DATAVRFYsessionVRFY <address>Verify that a mailbox exists (often disabled for security).
VRFY user@example.comEXPNsessionEXPN <list>Expand a mailing list (often disabled for security).
EXPN usersTentang alat ini
SMTP (Simple Mail Transfer Protocol) adalah protokol berbasis teks yang digunakan server surel untuk merelai dan mengirimkan email melalui internet. Baik pengembang yang mengintegrasikan fitur email maupun administrator sistem yang men-debug pengiriman sama-sama perlu memahami perintah-perintah intinya dengan jelas.
Referensi ini mencantumkan perintah SMTP penting seperti HELO/EHLO, MAIL FROM, RCPT TO, DATA, STARTTLS, AUTH, dan QUIT, masing-masing dengan sintaks, deskripsi singkat, dan contohnya. Anda dapat memakainya untuk menelusuri sesi manual melalui telnet atau openssl, mendiagnosis alasan sebuah pesan ditolak, atau sekadar mempelajari cara kerja protokol ini langkah demi langkah.
Perlu diingat bahwa server surel modern hampir selalu mewajibkan STARTTLS untuk enkripsi dan AUTH untuk pengiriman terautentikasi, sehingga sesi tanpa enkripsi sering kali ditolak. Anggaplah halaman ini sebagai alat bantu belajar dan rujukan, bukan panduan konfigurasi email untuk lingkungan produksi.
Pertanyaan yang Sering Diajukan
Implementasi Kode
import smtplib
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
def send_email_smtp(
smtp_host: str,
smtp_port: int,
username: str,
password: str,
from_addr: str,
to_addr: str,
subject: str,
body: str,
use_tls: bool = True
) -> bool:
"""Send email using SMTP with manual command flow."""
try:
with smtplib.SMTP(smtp_host, smtp_port) as server:
server.ehlo() # EHLO command
if use_tls:
server.starttls() # STARTTLS command
server.ehlo() # Re-EHLO after TLS
server.login(username, password) # AUTH command
msg = MIMEMultipart()
msg['From'] = from_addr
msg['To'] = to_addr
msg['Subject'] = subject
msg.attach(MIMEText(body, 'plain'))
# MAIL FROM, RCPT TO, DATA commands
server.sendmail(from_addr, to_addr, msg.as_string())
return True
except smtplib.SMTPException as e:
print(f"SMTP Error: {e}")
return False
# Test SMTP connection manually
def test_smtp_connection(host: str, port: int) -> dict:
import socket
try:
with smtplib.SMTP(host, port, timeout=5) as server:
banner = server.getwelcome()
ehlo_resp = server.ehlo()
return {
"connected": True,
"banner": banner.decode(),
"extensions": list(server.esmtp_features.keys())
}
except Exception as e:
return {"connected": False, "error": str(e)}
result = test_smtp_connection("smtp.gmail.com", 587)
print(result)Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.