본문으로 건너뛰기
🛠️ToolsShed

SMTP Commands Reference

상호작용형 예제가 포함된 SMTP 명령, 응답 코드, 이메일 프로토콜 흐름에 대한 완전한 참조입니다.

EHLOsession
EHLO <hostname>

Extended greeting; identifies the client and requests ESMTP extensions.

EHLO mail.example.com
HELOsession
HELO <hostname>

Basic SMTP greeting. Use EHLO for modern servers.

HELO mail.example.com
QUITsession
QUIT

Close the SMTP connection gracefully.

QUIT
STARTTLSsession
STARTTLS

Upgrade the connection to TLS encryption.

STARTTLS
NOOPsession
NOOP

No operation; used to keep the connection alive.

NOOP
RSETsession
RSET

Abort the current mail transaction and reset the session.

RSET
AUTHauth
AUTH <mechanism> [credentials]

Authenticate the client to the server (PLAIN, LOGIN, CRAM-MD5).

AUTH LOGIN
MAIL FROMmessage
MAIL FROM:<address>

Specify the sender envelope address.

MAIL FROM:<sender@example.com>
RCPT TOmessage
RCPT TO:<address>

Specify a recipient envelope address. Can be repeated.

RCPT TO:<recipient@example.com>
DATAmessage
DATA

Begin transmitting the message body. End with a line containing only a period.

DATA
VRFYsession
VRFY <address>

Verify that a mailbox exists (often disabled for security).

VRFY user@example.com
EXPNsession
EXPN <list>

Expand a mailing list (often disabled for security).

EXPN users

이 도구 소개

SMTP(Simple Mail Transfer Protocol)는 메일 서버가 인터넷에서 이메일을 중계하고 전달하기 위해 사용하는 텍스트 기반 프로토콜입니다. 이메일 기능을 연동하는 개발자와 메일 전송 문제를 디버깅하는 시스템 관리자 모두 핵심 명령어를 명확히 이해해야 합니다.

이 레퍼런스는 HELO/EHLO, MAIL FROM, RCPT TO, DATA, STARTTLS, AUTH, QUIT 등 필수 SMTP 명령어를 구문, 간단한 설명, 예시와 함께 정리해 둡니다. telnet이나 openssl로 수동 세션을 단계별로 진행하거나, 메시지가 거부된 원인을 진단하거나, 프로토콜의 동작 방식을 차근차근 학습하는 데 활용할 수 있습니다.

최신 메일 서버는 대부분 암호화를 위한 STARTTLS와 인증된 발송을 위한 AUTH를 요구하므로, 암호화되지 않은 평문 세션은 거부되는 경우가 많다는 점을 기억하세요. 이 페이지는 운영 환경 메일 설정 가이드가 아니라 학습 및 참고용 보조 자료로 활용하시기 바랍니다.

자주 묻는 질문

코드 구현

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.