Struct Mail

Source
pub struct Mail<'a> {
Show 14 fields pub to: Vec<Destination<'a>>, pub cc: Vec<&'a str>, pub bcc: Vec<&'a str>, pub from: &'a str, pub subject: &'a str, pub html: &'a str, pub text: &'a str, pub from_name: &'a str, pub reply_to: &'a str, pub date: &'a str, pub attachments: HashMap<String, String>, pub content: HashMap<String, &'a str>, pub headers: HashMap<String, &'a str>, pub x_smtpapi: &'a str,
}
Expand description

This is a representation of a valid SendGrid message. It has support for all of the fields in the V2 API.

Fields§

§to: Vec<Destination<'a>>

The list of people to whom the email will be sent.

§cc: Vec<&'a str>

The list of people that are CC’d in this email.

§bcc: Vec<&'a str>

The list of people that are BCC’d in this email.

§from: &'a str

The email address that will be used as sender.

§subject: &'a str

The subject field of the email.

§html: &'a str

When the client is sufficiently modern (this should almost always be the case), the email is displayed as HTML.

§text: &'a str

This is used as a fallback when either the client is too old or the HTML field was not provided.

§from_name: &'a str

This is the name that will be used as sender.

§reply_to: &'a str

This is the email address that is used as a reply to field.

§date: &'a str

The date added to the header of this email. For example Thu, 21 Dec 2000 16:01:07 +0200.

§attachments: HashMap<String, String>

The attachments of this email, smaller than 7MB.

§content: HashMap<String, &'a str>

Content IDs of the files to be used as inline images. Content IDs should match the content IDS used in the HTML markup.

§headers: HashMap<String, &'a str>

A collection of key/value pairs in JSON format. This is specifically for non-SendGrid custom extension headers. Each key represents a header name and the value the header value.

§Example
{"X-Accept-Language": "en", "X-Mailer": "MyApp"}
§x_smtpapi: &'a str

The X-SMTPAPI header that is used.

Implementations§

Source§

impl<'a> Mail<'a>

Source

pub fn new() -> Mail<'a>

Returns a new Mail struct to send with a client. All of the fields are initially empty.

Source

pub fn add_cc(self, data: &'a str) -> Mail<'a>

Adds a CC recipient to the Mail struct.

Source

pub fn add_to(self, data: Destination<'a>) -> Mail<'a>

Adds a to recipient to the Mail struct.

Source

pub fn add_from(self, data: &'a str) -> Mail<'a>

Set the from address for the Mail struct. This can be changed, but there is only one from address per message.

Source

pub fn add_subject(self, data: &'a str) -> Mail<'a>

Set the subject of the message.

Source

pub fn add_html(self, data: &'a str) -> Mail<'a>

This function sets the HTML content for the message.

Source

pub fn add_text(self, data: &'a str) -> Mail<'a>

Set the text content of the message.

Source

pub fn add_bcc(self, data: &'a str) -> Mail<'a>

Add a BCC address to the message.

Source

pub fn add_from_name(self, data: &'a str) -> Mail<'a>

Set the from name for the message.

Source

pub fn add_reply_to(self, data: &'a str) -> Mail<'a>

Set the reply to address for the message.

Source

pub fn add_date(self, data: &'a str) -> Mail<'a>

Set the date for the message. This must be a valid RFC 822 timestamp.

Source

pub fn build(self) -> Mail<'a>

Convenience method when using Mail as a builder.

Source

pub fn add_attachment<P: AsRef<Path>>(self, path: P) -> SendgridResult<Mail<'a>>

Add an attachment for the message. You can pass the name of a file as a path on the file system.

§Examples
let message = Mail::new()
    .add_attachment("/path/to/file/contents.txt");
Source

pub fn add_content(self, id: String, data: &'a str) -> Mail<'a>

Add content for inline images in the message.

Source

pub fn add_header(self, id: String, data: &'a str) -> Mail<'a>

Add a custom header for the message. These are usually prefixed with ‘X’ or ‘x’ per the RFC specifications.

Source

pub fn add_x_smtpapi(self, data: &'a str) -> Mail<'a>

Add an X-SMTPAPI string to the message. This can be done by using the serde_json crate to JSON encode a map or custom struct. Alternatively a regular String type can be escaped and used.

Trait Implementations§

Source§

impl<'a> Debug for Mail<'a>

Source§

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

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

impl<'a> Default for Mail<'a>

Source§

fn default() -> Mail<'a>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Mail<'a>

§

impl<'a> RefUnwindSafe for Mail<'a>

§

impl<'a> Send for Mail<'a>

§

impl<'a> Sync for Mail<'a>

§

impl<'a> Unpin for Mail<'a>

§

impl<'a> UnwindSafe for Mail<'a>

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> 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, 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