pub struct Mailbox { /* private fields */ }Expand description
A visible mailbox: optional display name plus email address.
Implementations§
Source§impl Mailbox
impl Mailbox
Sourcepub fn new(
display_name: Option<&str>,
address: impl AsRef<str>,
) -> Result<Mailbox, AddressValidationError>
pub fn new( display_name: Option<&str>, address: impl AsRef<str>, ) -> Result<Mailbox, AddressValidationError>
Creates a mailbox from optional display name text and address text.
Examples found in repository?
examples/email_facade_basic_usage.rs (line 4)
3fn main() -> Result<(), Box<dyn std::error::Error>> {
4 let mailbox = address::Mailbox::new(Some("Jane Doe"), "jane@example.com")?;
5 let message_id: id::MessageId = "welcome@example.com".parse()?;
6 let message = message::EmailMessage::plain_text("Welcome", "A short note.")
7 .with_header("From", mailbox.to_string())?;
8 let envelope = envelope::Envelope::new(envelope::EnvelopeSender::new("bounce@example.com")?)
9 .with_recipient(envelope::EnvelopeRecipient::new("jane@example.com")?);
10 let mailto_uri = mailto::MailtoBuilder::new()
11 .to("jane@example.com")?
12 .subject("Welcome")
13 .build();
14 let reply = smtp::SmtpReply::new(smtp::SmtpReplyCode::new(250)?, "OK")?;
15 let spf = auth::spf::SpfRecord::new().with_term(auth::spf::SpfTerm::new(
16 auth::spf::SpfQualifier::Fail,
17 auth::spf::SpfMechanism::All,
18 ));
19
20 assert_eq!(message.subject(), Some("Welcome"));
21 assert_eq!(message_id.to_string(), "<welcome@example.com>");
22 assert_eq!(envelope.recipients().len(), 1);
23 assert_eq!(
24 mailto_uri.to_string(),
25 "mailto:jane@example.com?subject=Welcome"
26 );
27 assert_eq!(reply.to_string(), "250 OK");
28 assert_eq!(spf.to_string(), "v=spf1 -all");
29
30 Ok(())
31}Sourcepub const fn from_address(address: EmailAddress) -> Mailbox
pub const fn from_address(address: EmailAddress) -> Mailbox
Creates a mailbox from an already validated address.
Sourcepub fn with_display_name(
self,
display_name: impl AsRef<str>,
) -> Result<Mailbox, AddressValidationError>
pub fn with_display_name( self, display_name: impl AsRef<str>, ) -> Result<Mailbox, AddressValidationError>
Adds a display name to the mailbox.
Sourcepub const fn display_name(&self) -> Option<&DisplayName>
pub const fn display_name(&self) -> Option<&DisplayName>
Returns the display name, when present.
Sourcepub const fn address(&self) -> &EmailAddress
pub const fn address(&self) -> &EmailAddress
Returns the mailbox address.
Trait Implementations§
Source§impl Ord for Mailbox
impl Ord for Mailbox
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 Mailbox
impl PartialOrd for Mailbox
impl Eq for Mailbox
impl StructuralPartialEq for Mailbox
Auto Trait Implementations§
impl Freeze for Mailbox
impl RefUnwindSafe for Mailbox
impl Send for Mailbox
impl Sync for Mailbox
impl Unpin for Mailbox
impl UnsafeUnpin for Mailbox
impl UnwindSafe for Mailbox
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