Skip to content

Commit fa1896e

Browse files
committed
Add an example
1 parent 2ed6625 commit fa1896e

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

Cargo.toml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ nom = "^7.0"
3030
thiserror = "1"
3131
tokio = { version = "1", features = ["time", "io-util"], optional = true }
3232

33-
3433
[dev-dependencies]
3534
env_logger = "^0.9"
3635
glob = "^0.3"
3736
criterion = "^0.3"
3837
async-std = { version = "1.11", features = ["unstable", "attributes"] }
39-
tokio = { version = "1", features = ["rt", "time", "macros"] }
38+
tokio = { version = "1", features = ["rt", "rt-multi-thread", "net", "time", "macros"] }
4039

41-
[features]
42-
default = [
43-
"runtime-tokio"
44-
]
40+
[[example]]
41+
name = "send"
42+
path = "examples/send.rs"
4543

44+
[features]
45+
default = ["runtime-tokio"]
4646
runtime-async-std = ["async-std"]
4747
runtime-tokio = ["tokio"]

examples/send.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use tokio::net::TcpStream;
2+
3+
pub type Error = Box<dyn std::error::Error + Send + Sync>;
4+
pub type Result<T> = std::result::Result<T, Error>;
5+
6+
use async_smtp::{Envelope, SendableEmail, SmtpClient, SmtpTransport};
7+
8+
#[tokio::main]
9+
async fn main() -> Result<()> {
10+
let stream = TcpStream::connect("127.0.0.1:2525").await?;
11+
let client = SmtpClient::new();
12+
let mut transport = SmtpTransport::new(client, stream).await?;
13+
14+
let email = SendableEmail::new(
15+
Envelope::new(
16+
Some("user@localhost".parse().unwrap()),
17+
vec!["root@localhost".parse().unwrap()],
18+
)?,
19+
"Hello world",
20+
);
21+
transport.send(email).await?;
22+
23+
Ok(())
24+
}

0 commit comments

Comments
 (0)