pub struct Attachment { /* private fields */ }
Expand description
SinglePart
builder for attachments
Allows building attachment parts easily.
Implementations§
Source§impl Attachment
impl Attachment
Sourcepub fn new(filename: String) -> Self
pub fn new(filename: String) -> Self
Create a new attachment
This attachment will be displayed as a normal attachment,
with the chosen filename
appearing as the file name.
use std::fs;
use lettre::message::{header::ContentType, Attachment};
let filename = String::from("invoice.pdf");
let filebody = fs::read("invoice.pdf")?;
let content_type = ContentType::parse("application/pdf").unwrap();
let attachment = Attachment::new(filename).body(filebody, content_type);
// The document `attachment` will show up as a normal attachment.
Sourcepub fn new_inline(content_id: String) -> Self
pub fn new_inline(content_id: String) -> Self
Create a new inline attachment
This attachment should be displayed inline into the message body:
<img src="cid:123">
use std::fs;
use lettre::message::{header::ContentType, Attachment};
let content_id = String::from("123");
let filebody = fs::read("image.jpg")?;
let content_type = ContentType::parse("image/jpeg").unwrap();
let attachment = Attachment::new_inline(content_id).body(filebody, content_type);
// The image `attachment` will display inline into the email.
Sourcepub fn body<T: IntoBody>(
self,
content: T,
content_type: ContentType,
) -> SinglePart
pub fn body<T: IntoBody>( self, content: T, content_type: ContentType, ) -> SinglePart
Build the attachment into a SinglePart
which can then be used to build the rest of the email
Look at the Complex MIME body example
to see how SinglePart
can be put into the email.
Trait Implementations§
Source§impl Clone for Attachment
impl Clone for Attachment
Source§fn clone(&self) -> Attachment
fn clone(&self) -> Attachment
Returns a copy 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 moreAuto 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