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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//! This provides user with easy to use email clients collection in rust. You can choose one or more of the email client and use this library to send emails easily.
//!
//! Features:
//! * Terminal client for local development
//! * Memory client for test cases
//! * SMTP client with tls and starttls, local support
//! * Easy configuration management
//! * Mailersend client with token and custom base url if needed.
//!
//! # Examples
//!
//! To integrate email client:
//!
//!```rust
//! use std::sync::mpsc;
//! # #[cfg(any(feature = "mailersend", feature = "terminal", feature = "smtp", feature = "memory", feature = "document-features", feature = "default"))]
//! use email_clients::clients::{EmailClient, get_email_client};
//! # #[cfg(feature = "mailersend")]
//! use email_clients::clients::mailersend::MailerSendConfig;
//! # #[cfg(feature = "memory")]
//! use email_clients::clients::memory::{MemoryClient, MemoryConfig};
//! # #[cfg(feature = "smtp")]
//! use email_clients::clients::smtp::SmtpConfig;
//! # #[cfg(feature = "terminal")]
//! use email_clients::clients::terminal::TerminalConfig;
//! use email_clients::configuration::EmailConfiguration;
//! use email_clients::email::{EmailAddress, EmailObject};
//!
//! let email = EmailObject {
//! sender: "test@example.com".into(),
//! to: vec![EmailAddress { name: "Mail".to_string(), email: "to@example.com".to_string() }],
//! subject: "subject".to_string(),
//! plain: "plain body".to_string(),
//! html: "<a>html body</a>".to_string(),
//! };
//!
//! // Choose any of the config as below:
//! // 1. Terminal client (needs terminal feature, enabled by default)
//! # #[cfg(feature = "terminal")]
//! let terminal_config: TerminalConfig = String::from("me@domain.com").into(); // Terminal config
//! // 2. Smtp config (needs smtp feature)
//! #[cfg(feature = "smtp")]
//! let smtp_config = SmtpConfig::default().sender("sender@example.com").relay("localhost");
//! // 3. Memory config (needs memory feature)
//! #[cfg(feature = "memory")]
//! let (tx, rx) = mpsc::sync_channel(2);
//! #[cfg(feature = "memory")]
//! let memory_config: MemoryConfig = String::from("me@domain.com").into();
//! // 4. Mailersend config (needs mailersend feature)
//! #[cfg(feature = "mailersend")]
//! let mailersend_config = MailerSendConfig::default().sender("sender@example.com").api_token("API_TOKEN");
//!
//! # #[cfg(feature = "terminal")]
//! # {
//! let email_configuration: EmailConfiguration = terminal_config.into(); // OR any of the other config
//! let client = get_email_client(email_configuration);
//! # tokio_test::block_on(async {
//! client.unwrap().send_emails(email).await.expect("Unable to send email");
//! # });
//! # }
//!
//! // For memory config, if you want to retain the receiver, you can do so using:
//! # #[cfg(feature = "memory")]
//! let memory_client = EmailClient::Memory(MemoryClient::with_tx(memory_config, tx));
//!```
//!
pub type Result<T> = Result;