1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
use std::result;
use async_stream_packed::TlsClientUpgrader;
use futures_util::io::{AsyncRead, AsyncWrite};
use lettre::message::Message;
use lettre::transport::smtp::error::Error;
use lettre::Envelope;
use crate::connection::AsyncConnection;
pub struct AsyncSession<'a, S, STU>
where
STU: TlsClientUpgrader<S>,
{
pub connection: &'a mut AsyncConnection<S, STU>,
}
impl<'a, S, STU> AsyncSession<'a, S, STU>
where
STU: TlsClientUpgrader<S> + Unpin,
S: AsyncRead + AsyncWrite + Unpin,
STU::Output: AsyncRead + AsyncWrite + Unpin,
{
pub(crate) fn new(connection: &'a mut AsyncConnection<S, STU>) -> Self {
Self { connection }
}
pub async fn send(&mut self, message: &Message) -> result::Result<(), Error> {
let raw = message.formatted();
self.send_raw(message.envelope(), &raw).await
}
pub async fn send_raw(
&mut self,
envelope: &Envelope,
email: &[u8],
) -> result::Result<(), Error> {
let _ = self.connection.send(envelope, email).await?;
self.connection.quit().await?;
Ok(())
}
}