feat(transport): Add features for SMTP and sendmail transport
This commit is contained in:
@@ -15,10 +15,10 @@ keywords = ["email", "smtp", "mailer"]
|
||||
travis-ci = { repository = "lettre/lettre" }
|
||||
|
||||
[dependencies]
|
||||
bufstream = "^0.1"
|
||||
log = "^0.3"
|
||||
native-tls = "^0.1"
|
||||
base64 = "^0.6"
|
||||
bufstream = { version = "^0.1", optional = true }
|
||||
native-tls = { version = "^0.1", optional = true }
|
||||
base64 = { version = "^0.6", optional = true }
|
||||
hex = { version = "^0.2", optional = true }
|
||||
rust-crypto = { version = "^0.2", optional = true }
|
||||
serde = { version = "^1.0", optional = true }
|
||||
@@ -29,8 +29,14 @@ serde_derive = { version = "^1.0", optional = true }
|
||||
env_logger = "^0.4"
|
||||
|
||||
[features]
|
||||
default = ["file-transport", "crammd5-auth"]
|
||||
default = ["file-transport", "crammd5-auth", "smtp-transport", "sendmail-transport"]
|
||||
unstable = []
|
||||
serde-impls = ["serde", "serde_derive"]
|
||||
file-transport = ["serde-impls", "serde_json"]
|
||||
crammd5-auth = ["rust-crypto", "hex"]
|
||||
crammd5-auth = ["rust-crypto", "hex"]
|
||||
smtp-transport = ["bufstream", "native-tls", "base64"]
|
||||
sendmail-transport = []
|
||||
|
||||
[[example]]
|
||||
name = "smtp"
|
||||
required-features = ["smtp-transport"]
|
||||
|
||||
@@ -8,12 +8,15 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
extern crate base64;
|
||||
#[cfg(feature = "crammd5-auth")]
|
||||
extern crate hex;
|
||||
#[cfg(feature = "crammd5-auth")]
|
||||
extern crate crypto;
|
||||
#[cfg(feature = "smtp-transport")]
|
||||
extern crate base64;
|
||||
#[cfg(feature = "smtp-transport")]
|
||||
extern crate bufstream;
|
||||
#[cfg(feature = "smtp-transport")]
|
||||
extern crate native_tls;
|
||||
#[cfg(feature = "file-transport")]
|
||||
extern crate serde_json;
|
||||
@@ -21,7 +24,9 @@ extern crate serde_json;
|
||||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
#[cfg(feature = "smtp-transport")]
|
||||
pub mod smtp;
|
||||
#[cfg(feature = "sendmail-transport")]
|
||||
pub mod sendmail;
|
||||
pub mod stub;
|
||||
#[cfg(feature = "file-transport")]
|
||||
@@ -29,8 +34,11 @@ pub mod file;
|
||||
|
||||
#[cfg(feature = "file-transport")]
|
||||
pub use file::FileEmailTransport;
|
||||
#[cfg(feature = "sendmail-transport")]
|
||||
pub use sendmail::SendmailTransport;
|
||||
#[cfg(feature = "smtp-transport")]
|
||||
pub use smtp::{SmtpTransport, ClientSecurity};
|
||||
#[cfg(feature = "smtp-transport")]
|
||||
pub use smtp::client::net::ClientTlsParameters;
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
use std::io::Read;
|
||||
|
||||
@@ -5,7 +5,6 @@ extern crate lettre;
|
||||
mod test {
|
||||
|
||||
use lettre::{EmailAddress, EmailTransport, SendableEmail, SimpleSendableEmail};
|
||||
#[cfg(feature = "file-transport")]
|
||||
use lettre::file::FileEmailTransport;
|
||||
use std::env::temp_dir;
|
||||
use std::fs::File;
|
||||
@@ -13,7 +12,6 @@ mod test {
|
||||
use std::io::Read;
|
||||
|
||||
#[test]
|
||||
#[cfg(feature = "file-transport")]
|
||||
fn file_transport() {
|
||||
let mut sender = FileEmailTransport::new(temp_dir());
|
||||
let email = SimpleSendableEmail::new(
|
||||
@@ -39,4 +37,5 @@ mod test {
|
||||
|
||||
remove_file(file).unwrap();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,25 @@
|
||||
extern crate lettre;
|
||||
|
||||
use lettre::{EmailAddress, EmailTransport, SimpleSendableEmail};
|
||||
use lettre::sendmail::SendmailTransport;
|
||||
#[cfg(test)]
|
||||
#[cfg(feature = "sendmail-transport")]
|
||||
mod test {
|
||||
|
||||
#[test]
|
||||
fn sendmail_transport_simple() {
|
||||
let mut sender = SendmailTransport::new();
|
||||
let email = SimpleSendableEmail::new(
|
||||
EmailAddress::new("user@localhost".to_string()),
|
||||
vec![EmailAddress::new("root@localhost".to_string())],
|
||||
"sendmail_id".to_string(),
|
||||
"Hello sendmail".to_string(),
|
||||
);
|
||||
use lettre::{EmailAddress, EmailTransport, SimpleSendableEmail};
|
||||
use lettre::sendmail::SendmailTransport;
|
||||
|
||||
#[test]
|
||||
fn sendmail_transport_simple() {
|
||||
let mut sender = SendmailTransport::new();
|
||||
let email = SimpleSendableEmail::new(
|
||||
EmailAddress::new("user@localhost".to_string()),
|
||||
vec![EmailAddress::new("root@localhost".to_string())],
|
||||
"sendmail_id".to_string(),
|
||||
"Hello sendmail".to_string(),
|
||||
);
|
||||
|
||||
let result = sender.send(&email);
|
||||
println!("{:?}", result);
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
let result = sender.send(&email);
|
||||
println!("{:?}", result);
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
@@ -1,19 +1,24 @@
|
||||
extern crate lettre;
|
||||
|
||||
use lettre::{ClientSecurity, EmailAddress, EmailTransport, SimpleSendableEmail, SmtpTransport};
|
||||
#[cfg(test)]
|
||||
#[cfg(feature = "smtp-transport")]
|
||||
mod test {
|
||||
|
||||
#[test]
|
||||
fn smtp_transport_simple() {
|
||||
let mut sender = SmtpTransport::builder("127.0.0.1:2525", ClientSecurity::None)
|
||||
.unwrap()
|
||||
.build();
|
||||
let email = SimpleSendableEmail::new(
|
||||
EmailAddress::new("user@localhost".to_string()),
|
||||
vec![EmailAddress::new("root@localhost".to_string())],
|
||||
"smtp_id".to_string(),
|
||||
"Hello smtp".to_string(),
|
||||
);
|
||||
use lettre::{ClientSecurity, EmailAddress, EmailTransport, SimpleSendableEmail, SmtpTransport};
|
||||
|
||||
#[test]
|
||||
fn smtp_transport_simple() {
|
||||
let mut sender = SmtpTransport::builder("127.0.0.1:2525", ClientSecurity::None)
|
||||
.unwrap()
|
||||
.build();
|
||||
let email = SimpleSendableEmail::new(
|
||||
EmailAddress::new("user@localhost".to_string()),
|
||||
vec![EmailAddress::new("root@localhost".to_string())],
|
||||
"smtp_id".to_string(),
|
||||
"Hello smtp".to_string(),
|
||||
);
|
||||
|
||||
sender.send(&email).unwrap();
|
||||
}
|
||||
|
||||
let result = sender.send(&email);
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user