EmailAddress

Struct EmailAddress 

Source
pub struct EmailAddress { /* private fields */ }

Implementations§

Source§

impl EmailAddress

Source

pub fn builder() -> EmailAddressBuilder<((), ())>

Create a builder for building EmailAddress. On the builder, call .name(...), .address(...) to set the values of the fields. Finally, call .build() to create the instance of EmailAddress.

Source§

impl EmailAddress

Source

pub fn address(address: &str) -> Self

Examples found in repository?
examples/basic.rs (line 19)
18fn send_html(recipient: &str, key: &str, domain: &str) {
19    let recipient = EmailAddress::address(recipient);
20    let message = Message {
21        to: vec![recipient],
22        subject: String::from("mailgun-rs"),
23        html: String::from("<h1>hello from mailgun</h1>"),
24        ..Default::default()
25    };
26    let client = Mailgun {
27        api_key: String::from(key),
28        domain: String::from(domain),
29    };
30    let sender = EmailAddress::name_address("no-reply", "no-reply@huatuo.xyz");
31
32    match client.send(MailgunRegion::US, &sender, message, None) {
33        Ok(_) => {
34            println!("successful");
35        }
36        Err(err) => {
37            println!("Error: {err}");
38        }
39    }
40}
41
42fn send_template(recipient: &str, key: &str, domain: &str) {
43    let mut template_vars = HashMap::new();
44    template_vars.insert(String::from("name"), String::from("Dongri Jin"));
45    let recipient = EmailAddress::address(recipient);
46    let message = Message {
47        to: vec![recipient],
48        subject: String::from("mailgun-rs"),
49        template: String::from("template-1"),
50        template_vars,
51        ..Default::default()
52    };
53    let client = Mailgun {
54        api_key: String::from(key),
55        domain: String::from(domain),
56    };
57    let sender = EmailAddress::name_address("no-reply", "no-reply@huatuo.xyz");
58
59    match client.send(MailgunRegion::US, &sender, message, None) {
60        Ok(_) => {
61            println!("successful");
62        }
63        Err(err) => {
64            println!("Error: {err}");
65        }
66    }
67}
68
69fn send_with_attachment(recipient: &str, key: &str, domain: &str) {
70    let recipient = EmailAddress::address(recipient);
71    let message = Message {
72        to: vec![recipient],
73        subject: String::from("mailgun-rs"),
74        html: String::from("<h1>hello from mailgun with attachment</h1>"),
75        ..Default::default()
76    };
77
78    let mut attachments = Vec::new();
79    for item in ["file-1", "file-2"] {
80        let file_name = format!("examples/attachments/sample-{item}.txt");
81        let absolute_path =
82            fs::canonicalize(Path::new(&file_name)).expect("cannot get absolute path");
83
84        attachments.push(
85            Attachment::builder()
86                .path(absolute_path.to_string_lossy().to_string())
87                .attachment_type(AttachmentType::Attachment)
88                .build(),
89        );
90    }
91
92    let client = Mailgun {
93        api_key: String::from(key),
94        domain: String::from(domain),
95    };
96
97    let sender = EmailAddress::name_address("no-reply", "no-reply@huatuo.xyz");
98
99    match client.send(MailgunRegion::US, &sender, message, Some(attachments)) {
100        Ok(_) => {
101            println!("successful");
102        }
103        Err(err) => {
104            println!("Error: {err}");
105        }
106    }
107}
108
109fn send_with_inline_attachment(recipient: &str, key: &str, domain: &str) {
110    let recipient = EmailAddress::address(recipient);
111    let message = Message {
112        to: vec![recipient],
113        subject: String::from("mailgun-rs"),
114        html: String::from(
115            "<h1>hello from mailgun with inline attachment</h1><img src=\"cid:inline.png\">",
116        ),
117        ..Default::default()
118    };
119
120    let mut attachments = Vec::new();
121    let file_name = "examples/attachments/sushi.png";
122    let absolute_path = fs::canonicalize(Path::new(&file_name)).expect("cannot get absolute path");
123
124    // Create an inline attachment
125    attachments.push(
126        Attachment::builder()
127            .path(absolute_path.to_string_lossy().to_string())
128            .attachment_type(AttachmentType::Inline)
129            .build(),
130    );
131
132    let client = Mailgun {
133        api_key: String::from(key),
134        domain: String::from(domain),
135    };
136
137    let sender = EmailAddress::name_address("no-reply", "no-reply@huatuo.xyz");
138
139    match client.send(MailgunRegion::US, &sender, message, Some(attachments)) {
140        Ok(_) => {
141            println!("successful");
142        }
143        Err(err) => {
144            println!("Error: {err}");
145        }
146    }
147}
Source

pub fn name_address(name: &str, address: &str) -> Self

Examples found in repository?
examples/basic.rs (line 30)
18fn send_html(recipient: &str, key: &str, domain: &str) {
19    let recipient = EmailAddress::address(recipient);
20    let message = Message {
21        to: vec![recipient],
22        subject: String::from("mailgun-rs"),
23        html: String::from("<h1>hello from mailgun</h1>"),
24        ..Default::default()
25    };
26    let client = Mailgun {
27        api_key: String::from(key),
28        domain: String::from(domain),
29    };
30    let sender = EmailAddress::name_address("no-reply", "no-reply@huatuo.xyz");
31
32    match client.send(MailgunRegion::US, &sender, message, None) {
33        Ok(_) => {
34            println!("successful");
35        }
36        Err(err) => {
37            println!("Error: {err}");
38        }
39    }
40}
41
42fn send_template(recipient: &str, key: &str, domain: &str) {
43    let mut template_vars = HashMap::new();
44    template_vars.insert(String::from("name"), String::from("Dongri Jin"));
45    let recipient = EmailAddress::address(recipient);
46    let message = Message {
47        to: vec![recipient],
48        subject: String::from("mailgun-rs"),
49        template: String::from("template-1"),
50        template_vars,
51        ..Default::default()
52    };
53    let client = Mailgun {
54        api_key: String::from(key),
55        domain: String::from(domain),
56    };
57    let sender = EmailAddress::name_address("no-reply", "no-reply@huatuo.xyz");
58
59    match client.send(MailgunRegion::US, &sender, message, None) {
60        Ok(_) => {
61            println!("successful");
62        }
63        Err(err) => {
64            println!("Error: {err}");
65        }
66    }
67}
68
69fn send_with_attachment(recipient: &str, key: &str, domain: &str) {
70    let recipient = EmailAddress::address(recipient);
71    let message = Message {
72        to: vec![recipient],
73        subject: String::from("mailgun-rs"),
74        html: String::from("<h1>hello from mailgun with attachment</h1>"),
75        ..Default::default()
76    };
77
78    let mut attachments = Vec::new();
79    for item in ["file-1", "file-2"] {
80        let file_name = format!("examples/attachments/sample-{item}.txt");
81        let absolute_path =
82            fs::canonicalize(Path::new(&file_name)).expect("cannot get absolute path");
83
84        attachments.push(
85            Attachment::builder()
86                .path(absolute_path.to_string_lossy().to_string())
87                .attachment_type(AttachmentType::Attachment)
88                .build(),
89        );
90    }
91
92    let client = Mailgun {
93        api_key: String::from(key),
94        domain: String::from(domain),
95    };
96
97    let sender = EmailAddress::name_address("no-reply", "no-reply@huatuo.xyz");
98
99    match client.send(MailgunRegion::US, &sender, message, Some(attachments)) {
100        Ok(_) => {
101            println!("successful");
102        }
103        Err(err) => {
104            println!("Error: {err}");
105        }
106    }
107}
108
109fn send_with_inline_attachment(recipient: &str, key: &str, domain: &str) {
110    let recipient = EmailAddress::address(recipient);
111    let message = Message {
112        to: vec![recipient],
113        subject: String::from("mailgun-rs"),
114        html: String::from(
115            "<h1>hello from mailgun with inline attachment</h1><img src=\"cid:inline.png\">",
116        ),
117        ..Default::default()
118    };
119
120    let mut attachments = Vec::new();
121    let file_name = "examples/attachments/sushi.png";
122    let absolute_path = fs::canonicalize(Path::new(&file_name)).expect("cannot get absolute path");
123
124    // Create an inline attachment
125    attachments.push(
126        Attachment::builder()
127            .path(absolute_path.to_string_lossy().to_string())
128            .attachment_type(AttachmentType::Inline)
129            .build(),
130    );
131
132    let client = Mailgun {
133        api_key: String::from(key),
134        domain: String::from(domain),
135    };
136
137    let sender = EmailAddress::name_address("no-reply", "no-reply@huatuo.xyz");
138
139    match client.send(MailgunRegion::US, &sender, message, Some(attachments)) {
140        Ok(_) => {
141            println!("successful");
142        }
143        Err(err) => {
144            println!("Error: {err}");
145        }
146    }
147}

Trait Implementations§

Source§

impl Clone for EmailAddress

Source§

fn clone(&self) -> EmailAddress

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EmailAddress

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for EmailAddress

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<&str> for EmailAddress

Source§

fn from(address: &str) -> Self

Converts to this type from the input type.
Source§

impl From<(&str, &str)> for EmailAddress

Source§

fn from((name, address): (&str, &str)) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for EmailAddress

Source§

fn eq(&self, other: &EmailAddress) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Eq for EmailAddress

Source§

impl StructuralPartialEq for EmailAddress

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,