Merge pull request #176 from amousset/method-builder
Add methods to create builder and reexport Transport types
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
extern crate lettre;
|
||||
|
||||
use lettre::{EmailAddress, EmailTransport, SimpleSendableEmail};
|
||||
use lettre::smtp::{SecurityLevel, SmtpTransportBuilder};
|
||||
use lettre::{EmailAddress, EmailTransport, SimpleSendableEmail, SecurityLevel, SmtpTransport};
|
||||
|
||||
fn main() {
|
||||
let email = SimpleSendableEmail::new(
|
||||
@@ -12,7 +11,7 @@ fn main() {
|
||||
);
|
||||
|
||||
// Open a local connection on port 25
|
||||
let mut mailer = SmtpTransportBuilder::localhost()
|
||||
let mut mailer = SmtpTransport::builder_localhost()
|
||||
.unwrap()
|
||||
.security_level(SecurityLevel::Opportunistic)
|
||||
.build();
|
||||
|
||||
@@ -28,6 +28,14 @@ pub mod sendmail;
|
||||
pub mod stub;
|
||||
#[cfg(feature = "file-transport")]
|
||||
pub mod file;
|
||||
|
||||
pub use smtp::SmtpTransport;
|
||||
pub use smtp::SecurityLevel;
|
||||
#[cfg(feature = "file-transport")]
|
||||
pub use file::FileEmailTransport;
|
||||
pub use stub::StubEmailTransport;
|
||||
pub use sendmail::SendmailTransport;
|
||||
|
||||
use std::fmt;
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
|
||||
@@ -18,9 +18,7 @@
|
||||
//! This is the most basic example of usage:
|
||||
//!
|
||||
//! ```rust,no_run
|
||||
//! use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress};
|
||||
//! use lettre::smtp::SmtpTransportBuilder;
|
||||
//! use lettre::smtp::SecurityLevel;
|
||||
//! use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress, SmtpTransport, SecurityLevel};
|
||||
//!
|
||||
//! let email = SimpleSendableEmail::new(
|
||||
//! EmailAddress::new("user@localhost".to_string()),
|
||||
@@ -31,7 +29,7 @@
|
||||
//!
|
||||
//! // Open a local connection on port 25
|
||||
//! let mut mailer =
|
||||
//! SmtpTransportBuilder::localhost().unwrap().security_level(SecurityLevel::Opportunistic).build();
|
||||
//! SmtpTransport::builder_localhost().unwrap().security_level(SecurityLevel::Opportunistic).build();
|
||||
//! // Send the email
|
||||
//! let result = mailer.send(email);
|
||||
//!
|
||||
@@ -41,11 +39,9 @@
|
||||
//! #### Complete example
|
||||
//!
|
||||
//! ```rust,no_run
|
||||
//! use lettre::smtp::{SecurityLevel, SmtpTransport,
|
||||
//! SmtpTransportBuilder};
|
||||
//! use lettre::smtp::authentication::{Credentials, Mechanism};
|
||||
//! use lettre::smtp::SUBMISSION_PORT;
|
||||
//! use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress};
|
||||
//! use lettre::{SimpleSendableEmail, EmailTransport, EmailAddress, SmtpTransport, SecurityLevel};
|
||||
//! use lettre::smtp::extension::ClientId;
|
||||
//!
|
||||
//! let email = SimpleSendableEmail::new(
|
||||
@@ -56,7 +52,7 @@
|
||||
//! );
|
||||
//!
|
||||
//! // Connect to a remote server on a custom port
|
||||
//! let mut mailer = SmtpTransportBuilder::new(("server.tld",
|
||||
//! let mut mailer = SmtpTransport::builder(("server.tld",
|
||||
//! SUBMISSION_PORT)).unwrap()
|
||||
//! // Set the name sent during EHLO/HELO, default is `localhost`
|
||||
//! .hello_name(ClientId::Domain("my.hostname.tld".to_string()))
|
||||
@@ -225,11 +221,6 @@ impl SmtpTransportBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/// Creates a new local SMTP client to port 25
|
||||
pub fn localhost() -> Result<SmtpTransportBuilder, Error> {
|
||||
SmtpTransportBuilder::new(("localhost", SMTP_PORT))
|
||||
}
|
||||
|
||||
/// Use STARTTLS with a specific context
|
||||
pub fn tls_connector(mut self, tls_context: TlsConnector) -> SmtpTransportBuilder {
|
||||
self.tls_connector = tls_context;
|
||||
@@ -346,6 +337,15 @@ macro_rules! try_smtp (
|
||||
);
|
||||
|
||||
impl SmtpTransport {
|
||||
/// TODO
|
||||
pub fn builder<A: ToSocketAddrs>(addr: A) -> Result<SmtpTransportBuilder, Error> {
|
||||
SmtpTransportBuilder::new(addr)
|
||||
}
|
||||
/// Creates a new local SMTP client to port 25
|
||||
pub fn builder_localhost() -> Result<SmtpTransportBuilder, Error> {
|
||||
SmtpTransportBuilder::new(("localhost", SMTP_PORT))
|
||||
}
|
||||
|
||||
/// Creates a new SMTP client
|
||||
///
|
||||
/// It does not connect to the server, but only creates the `SmtpTransport`
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
extern crate lettre;
|
||||
extern crate lettre_email;
|
||||
|
||||
use lettre::EmailTransport;
|
||||
use lettre::smtp::SmtpTransportBuilder;
|
||||
use lettre::{SmtpTransport, EmailTransport};
|
||||
use lettre_email::email::EmailBuilder;
|
||||
|
||||
fn main() {
|
||||
@@ -17,7 +16,7 @@ fn main() {
|
||||
.unwrap();
|
||||
|
||||
// Open a local connection on port 25
|
||||
let mut mailer = SmtpTransportBuilder::localhost().unwrap().build();
|
||||
let mut mailer = SmtpTransport::builder_localhost().unwrap().build();
|
||||
// Send the email
|
||||
let result = mailer.send(email);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user