pub struct Address { /* private fields */ }Expand description
Represents an email address with a user and a domain name.
This type contains email in canonical form (user@domain.tld).
NOTE: Enable feature “serde” to be able to serialize/deserialize it using serde.
§Examples
You can create an Address from a user and a domain:
use lettre::Address;
let address = Address::new("user", "email.com")?;
assert_eq!(address.user(), "user");
assert_eq!(address.domain(), "email.com");You can also create an Address from a string literal by parsing it:
use lettre::Address;
let address = "user@email.com".parse::<Address>()?;
assert_eq!(address.user(), "user");
assert_eq!(address.domain(), "email.com");Implementations§
Source§impl Address
impl Address
Sourcepub fn new<U: AsRef<str>, D: AsRef<str>>(
user: U,
domain: D,
) -> Result<Self, AddressError>
pub fn new<U: AsRef<str>, D: AsRef<str>>( user: U, domain: D, ) -> Result<Self, AddressError>
Creates a new email address from a user and domain.
§Examples
use lettre::Address;
let address = Address::new("user", "email.com")?;
let expected = "user@email.com".parse::<Address>()?;
assert_eq!(expected, address);Sourcepub fn new_dangerous<U: AsRef<str>, D: AsRef<str>>(user: U, domain: D) -> Self
pub fn new_dangerous<U: AsRef<str>, D: AsRef<str>>(user: U, domain: D) -> Self
Creates a new email address from a user and domain, without validation.
§Danger
Use this method only if you are completely sure your input is known and valid, but rejected by the parser.
Do not use this method if the contents of either user or domain are unknown and/or obtained from user input.
Prefer using Address::new() instead if possible.
§Examples
use lettre::Address;
let address = Address::new_dangerous(
"a_very_long_email_address_that_would_normally_be_rejected_but_it_is_valid_trust_me",
"email.com",
);
assert_eq!(
address.user(),
"a_very_long_email_address_that_would_normally_be_rejected_but_it_is_valid_trust_me"
);
assert_eq!(address.domain(), "email.com");Trait Implementations§
Source§impl<'de> Deserialize<'de> for Address
Available on crate feature serde only.
impl<'de> Deserialize<'de> for Address
Available on crate feature
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl Eq for Address
Source§impl Ord for Address
impl Ord for Address
1.21.0 (const: unstable) · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialOrd for Address
impl PartialOrd for Address
impl StructuralPartialEq for Address
Auto Trait Implementations§
impl Freeze for Address
impl RefUnwindSafe for Address
impl Send for Address
impl Sync for Address
impl Unpin for Address
impl UnsafeUnpin for Address
impl UnwindSafe for Address
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more