smtp_send 0.1.18

SMTP email sending library with built-in DKIM signing and MX lookup support. / 支持内置 DKIM 签名和 MX 记录查询的 SMTP 邮件发送库。
Documentation
use mail_send::{Result, SmtpClient, SmtpClientBuilder, smtp::message::IntoMessage};
use tokio::net::TcpStream;
use tokio_rustls::client::TlsStream;

use crate::Signer;

pub struct Smtp<'a> {
  pub client: SmtpClient<TlsStream<TcpStream>>,
  signer: &'a Signer,
}

impl<'a> Smtp<'a> {
  pub async fn connect(server: &str, signer: &'a Signer) -> Result<Self> {
    Ok(Self {
      signer,
      client: SmtpClientBuilder::new(server, 25)
        .implicit_tls(false)
        .connect()
        .await?,
    })
  }

  pub async fn send(&mut self, mail: impl IntoMessage<'_>) -> Result<()> {
    self.client.send_signed(mail, self.signer).await
  }
}