|
|
| smtp_socket ()=default |
| | 默认构造函数
|
| | smtp_socket (native_handle_type fd) noexcept |
| | 从原生句柄构造
|
| void | connect (const ip_address &addr, const string &domain="localhost", tls_mode mode=tls_mode::none, const ssl_context *ctx=nullptr, const string &sni_hostname="") |
| | 连接SMTP服务器(IP)
|
| void | connect (const string &hostname, ports port, const string &domain="localhost", tls_mode mode=tls_mode::none, dns_client *dns=nullptr, const ssl_context *ctx=nullptr, const string &sni_hostname="") |
| | 连接SMTP服务器(域名)
|
| starttls_result | starttls (const ssl_context &ctx, const string &sni_hostname="") |
| | 执行STARTTLS升级
|
|
void | disconnect () |
| | 断开连接,发送QUIT命令
|
| void | authenticate (const string &username, const string &password, auth_method method=auth_method::plain) |
| | SMTP认证
|
| void | send (const smtp_message &msg) |
| | 发送邮件
|
|
void | noop () |
| | 发送NOOP命令
|
| NEFORCE_NODISCARD bool | is_connected () const noexcept |
| | 是否已连接
|
| NEFORCE_NODISCARD bool | is_tls_active () const noexcept |
| | TLS是否已激活
|
| NEFORCE_NODISCARD bool | verify_peer () const |
| | 验证服务器证书
|
| NEFORCE_NODISCARD string | cipher_name () const |
| | 获取当前TLS密码套件名
|
| NEFORCE_NODISCARD string | tls_version () const |
| | 获取当前TLS版本
|
|
| ip_socket ()=default |
| | 默认构造函数
|
| | ip_socket (const native_handle_type fd) noexcept |
| | 从原生句柄构造
|
|
| ~ip_socket () override=default |
| | 析构函数
|
| NEFORCE_NODISCARD int | address_family () const noexcept |
| | 获取地址族
|
| NEFORCE_NODISCARD bool | is_ipv4 () const noexcept |
| | 检查是否为IPv4 socket
|
| NEFORCE_NODISCARD bool | is_ipv6 () const noexcept |
| | 检查是否为IPv6 socket
|
| virtual void | connect (const ip_address &endpoint) |
| | 连接到远程端点(TCP客户端)
|
| bool | close () noexcept override |
| | 关闭socket
|
|
| socket_base () |
| | 默认构造函数
|
| | socket_base (const native_handle_type fd) noexcept |
| | 从原生句柄构造
|
| | socket_base (socket_base &&other) noexcept |
| | 移动构造函数
|
| socket_base & | operator= (socket_base &&other) noexcept |
| | 移动赋值运算符
|
|
virtual | ~socket_base () |
| | 析构函数
|
| NEFORCE_NODISCARD native_handle_type | native_handle () const noexcept |
| | 获取原生句柄
|
| NEFORCE_NODISCARD bool | is_open () const noexcept |
| | 检查socket是否已打开
|
| | operator bool () const noexcept |
| | 布尔转换运算符
|
| void | open (int family, int type, int protocol) |
| | 打开socket
|
| bool | try_open (int family, int type, int protocol) noexcept |
| | 尝试打开socket(不抛出异常)
|
| bool | set_nonblocking (bool enable) noexcept |
| | 设置非阻塞模式
|
| bool | shutdown_send () noexcept |
| | 关闭发送方向
|
| bool | shutdown_receive () noexcept |
| | 关闭接收方向
|
| bool | shutdown_both () noexcept |
| | 关闭双向通信
|
| bool | set_option (int level, int optname, const void *value, ::socklen_t len) noexcept |
| | 设置socket选项
|
| bool | get_option (int level, int optname, void *optval, ::socklen_t *optlen) const noexcept |
| | 获取socket选项
|
| bool | set_reuse_address (bool enable=true) noexcept |
| | 设置地址重用(SO_REUSEADDR)
|
| bool | set_reuse_port (bool enable=true) noexcept |
| | 设置端口重用(SO_REUSEPORT)
|
| bool | set_keep_alive (bool enable=true) noexcept |
| | 设置TCP KeepAlive
|
| bool | set_tcp_nodelay (bool enable=true) noexcept |
| | 设置TCP_NODELAY(禁用Nagle算法)
|
| bool | set_receive_buffer_size (int size) noexcept |
| | 设置接收缓冲区大小
|
| bool | set_send_buffer_size (int size) noexcept |
| | 设置发送缓冲区大小
|
| bool | set_send_timeout (milliseconds timeout) noexcept |
| | 设置发送超时时间
|
| bool | set_receive_timeout (milliseconds timeout) noexcept |
| | 设置接收超时时间
|
| NEFORCE_NODISCARD optional< ip_address > | local_endpoint () const |
| | 获取本地端点地址
|
| NEFORCE_NODISCARD optional< ip_address > | remote_endpoint () const |
| | 获取远程端点地址
|
| void | bind (const ip_address &endpoint) |
| | 绑定socket到本地地址
|
| void | listen (int backlog) |
| | 开始监听连接(TCP)
|
| NEFORCE_NODISCARD native_handle_type | release () noexcept |
| | 释放socket所有权
|
SMTP Socket类
实现SMTP客户端协议,支持完整的邮件发送流程。 支持多种连接方式和认证机制。
主要功能:
- SMTP服务器连接(支持IP和域名)
- TLS/SSL加密(隐式TLS、STARTTLS)
- 认证(PLAIN、LOGIN)
- 邮件发送(支持收件人、抄送、密送、HTML邮件)
- EHLO/HELO协议协商
- DNS解析
使用示例:
ctx.load_verify_locations("ca-bundle.crt");
smtp.
connect(
"smtp.qq.com", ports::smtp,
"example.com",
msg.
from =
"sender@qq.com";
msg.
to = {
"recipient@example.com"};
msg.
body =
"Hello, this is a test email!";
void authenticate(const string &username, const string &password, auth_method method=auth_method::plain)
SMTP认证
void disconnect()
断开连接,发送QUIT命令
void send(const smtp_message &msg)
发送邮件
void connect(const ip_address &addr, const string &domain="localhost", tls_mode mode=tls_mode::none, const ssl_context *ctx=nullptr, const string &sni_hostname="")
连接SMTP服务器(IP)
smtp_socket()=default
默认构造函数
@ starttls
STARTTLS(从明文升级到TLS)
vector< string > to
收件人地址列表
在文件 smtp_socket.hpp 第 114 行定义.