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>
impl<'a> Mail<'a>
Sourcepub fn new() -> Mail<'a>
pub fn new() -> Mail<'a>
Returns a new Mail struct to send with a client. All of the fields are initially empty.
Sourcepub fn add_to(self, data: Destination<'a>) -> Mail<'a>
pub fn add_to(self, data: Destination<'a>) -> Mail<'a>
Adds a to recipient to the Mail struct.
Sourcepub fn add_from(self, data: &'a str) -> Mail<'a>
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.
Sourcepub fn add_subject(self, data: &'a str) -> Mail<'a>
pub fn add_subject(self, data: &'a str) -> Mail<'a>
Set the subject of the message.
Sourcepub fn add_html(self, data: &'a str) -> Mail<'a>
pub fn add_html(self, data: &'a str) -> Mail<'a>
This function sets the HTML content for the message.
Sourcepub fn add_from_name(self, data: &'a str) -> Mail<'a>
pub fn add_from_name(self, data: &'a str) -> Mail<'a>
Set the from name for the message.
Sourcepub fn add_reply_to(self, data: &'a str) -> Mail<'a>
pub fn add_reply_to(self, data: &'a str) -> Mail<'a>
Set the reply to address for the message.
Sourcepub fn add_date(self, data: &'a str) -> Mail<'a>
pub fn add_date(self, data: &'a str) -> Mail<'a>
Set the date for the message. This must be a valid RFC 822 timestamp.
Sourcepub fn add_attachment<P: AsRef<Path>>(self, path: P) -> SendgridResult<Mail<'a>>
pub fn add_attachment<P: AsRef<Path>>(self, path: P) -> SendgridResult<Mail<'a>>
Sourcepub fn add_content(self, id: String, data: &'a str) -> Mail<'a>
pub fn add_content(self, id: String, data: &'a str) -> Mail<'a>
Add content for inline images in the message.
Sourcepub fn add_header(self, id: String, data: &'a str) -> Mail<'a>
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.
Sourcepub fn add_x_smtpapi(self, data: &'a str) -> Mail<'a>
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.