pub struct Attachment {
pub path: String,
pub attachment_type: AttachmentType,
}
Fields§
§path: String
§attachment_type: AttachmentType
Implementations§
Source§impl Attachment
impl Attachment
Sourcepub fn builder() -> AttachmentBuilder<((), ())>
pub fn builder() -> AttachmentBuilder<((), ())>
Create a builder for building Attachment
.
On the builder, call .path(...)
, .attachment_type(...)
(optional) to set the values of the fields.
Finally, call .build()
to create the instance of Attachment
.
Examples found in repository?
examples/basic.rs (line 85)
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 Attachment
impl Clone for Attachment
Source§fn clone(&self) -> Attachment
fn clone(&self) -> Attachment
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for Attachment
impl Debug for Attachment
Source§impl From<&str> for Attachment
impl From<&str> for Attachment
Auto Trait Implementations§
impl Freeze for Attachment
impl RefUnwindSafe for Attachment
impl Send for Attachment
impl Sync for Attachment
impl Unpin for Attachment
impl UnwindSafe for Attachment
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