[][src]Struct sendgrid::Mail

pub struct Mail<'a> {
    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,
}

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

impl<'a> Mail<'a>[src]

pub fn new() -> Mail<'a>[src]

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

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

Adds a CC recipient to the Mail struct.

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

Adds a to recipient to the Mail struct.

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

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

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

Set the subject of the message.

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

This function sets the HTML content for the message.

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

Set the text content of the message.

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

Add a BCC address to the message.

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

Set the from name for the message.

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

Set the reply to address for the message.

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

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

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

Convenience method when using Mail as a builder.

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

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

Examples

This example is not tested
let message = Mail::new()
    .add_attachment("/path/to/file/contents.txt");

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

Add content for inline images in the message.

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

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

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

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

impl<'a> Debug for Mail<'a>[src]

impl<'a> Default for Mail<'a>[src]

Auto Trait Implementations

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.