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 new_inline_with_name(content_id: String, name: String) -> Self
 
pub fn new_inline_with_name(content_id: String, name: String) -> Self
Create a new inline attachment giving it a name
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 file_name = String::from("image.jpg");
let filebody = fs::read(&file_name)?;
let content_type = ContentType::parse("image/jpeg").unwrap();
let attachment =
    Attachment::new_inline_with_name(content_id, file_name).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
Source§impl<T> CloneToUninit for Twhere
    T: Clone,
 
impl<T> CloneToUninit for Twhere
    T: Clone,
Source§impl<T> IntoEither for T
 
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
 
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts 
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
 
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts 
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more