1 from _typeshed import Self
2 from email.message import Message as _Message
3 from socket import socket
4 from ssl import SSLContext
5 from types import TracebackType
6 from typing import Any, Dict, Pattern, Protocol, Sequence, Tuple, Type, Union, overload
8 _Reply = Tuple[int, bytes]
9 _SendErrs = Dict[str, _Reply]
10 # Should match source_address for socket.create_connection
11 _SourceAddress = Tuple[Union[bytearray, bytes, str], int]
18 OLDSTYLE_AUTH: Pattern[str]
20 class SMTPException(OSError): ...
21 class SMTPNotSupportedError(SMTPException): ...
22 class SMTPServerDisconnected(SMTPException): ...
24 class SMTPResponseException(SMTPException):
26 smtp_error: bytes | str
27 args: tuple[int, bytes | str] | tuple[int, bytes, str]
28 def __init__(self, code: int, msg: bytes | str) -> None: ...
30 class SMTPSenderRefused(SMTPResponseException):
34 args: tuple[int, bytes, str]
35 def __init__(self, code: int, msg: bytes, sender: str) -> None: ...
37 class SMTPRecipientsRefused(SMTPException):
39 args: tuple[_SendErrs]
40 def __init__(self, recipients: _SendErrs) -> None: ...
42 class SMTPDataError(SMTPResponseException): ...
43 class SMTPConnectError(SMTPResponseException): ...
44 class SMTPHeloError(SMTPResponseException): ...
45 class SMTPAuthenticationError(SMTPResponseException): ...
47 def quoteaddr(addrstring: str) -> str: ...
48 def quotedata(data: str) -> str: ...
50 class _AuthObject(Protocol):
52 def __call__(self, challenge: None = ...) -> str | None: ...
54 def __call__(self, challenge: bytes) -> str: ...
59 # Type of file should match what socket.makefile() returns
61 helo_resp: bytes | None
63 ehlo_resp: bytes | None
67 esmtp_features: dict[str, str]
69 source_address: _SourceAddress | None
75 local_hostname: str | None = ...,
77 source_address: _SourceAddress | None = ...,
79 def __enter__(self: Self) -> Self: ...
81 self, exc_type: Type[BaseException] | None, exc_value: BaseException | None, tb: TracebackType | None
83 def set_debuglevel(self, debuglevel: int) -> None: ...
84 def connect(self, host: str = ..., port: int = ..., source_address: _SourceAddress | None = ...) -> _Reply: ...
85 def send(self, s: bytes | str) -> None: ...
86 def putcmd(self, cmd: str, args: str = ...) -> None: ...
87 def getreply(self) -> _Reply: ...
88 def docmd(self, cmd: str, args: str = ...) -> _Reply: ...
89 def helo(self, name: str = ...) -> _Reply: ...
90 def ehlo(self, name: str = ...) -> _Reply: ...
91 def has_extn(self, opt: str) -> bool: ...
92 def help(self, args: str = ...) -> bytes: ...
93 def rset(self) -> _Reply: ...
94 def noop(self) -> _Reply: ...
95 def mail(self, sender: str, options: Sequence[str] = ...) -> _Reply: ...
96 def rcpt(self, recip: str, options: Sequence[str] = ...) -> _Reply: ...
97 def data(self, msg: bytes | str) -> _Reply: ...
98 def verify(self, address: str) -> _Reply: ...
100 def expn(self, address: str) -> _Reply: ...
101 def ehlo_or_helo_if_needed(self) -> None: ...
104 def auth(self, mechanism: str, authobject: _AuthObject, *, initial_response_ok: bool = ...) -> _Reply: ...
106 def auth_cram_md5(self, challenge: None = ...) -> None: ...
108 def auth_cram_md5(self, challenge: bytes) -> str: ...
109 def auth_plain(self, challenge: bytes | None = ...) -> str: ...
110 def auth_login(self, challenge: bytes | None = ...) -> str: ...
111 def login(self, user: str, password: str, *, initial_response_ok: bool = ...) -> _Reply: ...
112 def starttls(self, keyfile: str | None = ..., certfile: str | None = ..., context: SSLContext | None = ...) -> _Reply: ...
116 to_addrs: str | Sequence[str],
118 mail_options: Sequence[str] = ...,
119 rcpt_options: Sequence[str] = ...,
124 from_addr: str | None = ...,
125 to_addrs: str | Sequence[str] | None = ...,
126 mail_options: Sequence[str] = ...,
127 rcpt_options: Sequence[str] = ...,
129 def close(self) -> None: ...
130 def quit(self) -> _Reply: ...
132 class SMTP_SSL(SMTP):
141 local_hostname: str | None = ...,
142 keyfile: str | None = ...,
143 certfile: str | None = ...,
144 timeout: float = ...,
145 source_address: _SourceAddress | None = ...,
146 context: SSLContext | None = ...,
153 self, host: str = ..., port: int = ..., local_hostname: str | None = ..., source_address: _SourceAddress | None = ...