pub struct MessageBuilder(/* private fields */);
Expand description
Represents a builder for SendGrid messages.
Implementations§
Source§impl MessageBuilder
impl MessageBuilder
Sourcepub fn new() -> MessageBuilder
pub fn new() -> MessageBuilder
Creates a new message builder.
Sourcepub fn to<T>(self, email: T) -> MessageBuilder
pub fn to<T>(self, email: T) -> MessageBuilder
Appends the given “to” email address to the first personalization of the message.
§Examples
let message = MessageBuilder::new().to("foo@example.com").finish();
assert_eq!(message.personalizations[0].to[0].email, "foo@example.com");
assert_eq!(message.personalizations[0].to[0].name, None);
Sourcepub fn to_with_name<T, U>(self, email: T, name: U) -> MessageBuilder
pub fn to_with_name<T, U>(self, email: T, name: U) -> MessageBuilder
Appends the given “to” email address to the first personalization of the message.
§Examples
let message = MessageBuilder::new().to_with_name("foo@example.com", "Peter").finish();
assert_eq!(message.personalizations[0].to[0].email, "foo@example.com");
assert_eq!(message.personalizations[0].to[0].name, Some("Peter".to_owned()));
Sourcepub fn tos<T>(self, addresses: T) -> MessageBuilderwhere
T: IntoIterator<Item = EmailAddress>,
pub fn tos<T>(self, addresses: T) -> MessageBuilderwhere
T: IntoIterator<Item = EmailAddress>,
Appends the given “to” email addresses to the first personalization of the message.
§Examples
let message = MessageBuilder::new().tos(
vec![
EmailAddress::new("foo@example.com"),
EmailAddress::new_with_name("bar@example.com", "Peter"),
]).finish();
assert_eq!(message.personalizations[0].to[0].email, "foo@example.com");
assert_eq!(message.personalizations[0].to[0].name, None);
assert_eq!(message.personalizations[0].to[1].email, "bar@example.com");
assert_eq!(message.personalizations[0].to[1].name, Some("Peter".to_owned()));
Sourcepub fn cc<T>(self, email: T) -> MessageBuilder
pub fn cc<T>(self, email: T) -> MessageBuilder
Appends the given “cc” email address to the first personalization of the message.
§Examples
let message = MessageBuilder::new().cc("foo@example.com").finish();
assert_eq!(message.personalizations[0].cc[0].email, "foo@example.com");
assert_eq!(message.personalizations[0].cc[0].name, None);
Sourcepub fn cc_with_name<T, U>(self, email: T, name: U) -> MessageBuilder
pub fn cc_with_name<T, U>(self, email: T, name: U) -> MessageBuilder
Appends the given “cc” email address to the first personalization of the message.
§Examples
let message = MessageBuilder::new().cc_with_name("foo@example.com", "Peter").finish();
assert_eq!(message.personalizations[0].cc[0].email, "foo@example.com");
assert_eq!(message.personalizations[0].cc[0].name, Some("Peter".to_owned()));
Sourcepub fn ccs<T>(self, addresses: T) -> MessageBuilderwhere
T: IntoIterator<Item = EmailAddress>,
pub fn ccs<T>(self, addresses: T) -> MessageBuilderwhere
T: IntoIterator<Item = EmailAddress>,
Appends the given “cc” email addresses to the first personalization of the message.
§Examples
let message = MessageBuilder::new().ccs(
vec![
EmailAddress::new("foo@example.com"),
EmailAddress::new_with_name("bar@example.com", "Peter"),
]).finish();
assert_eq!(message.personalizations[0].cc[0].email, "foo@example.com");
assert_eq!(message.personalizations[0].cc[0].name, None);
assert_eq!(message.personalizations[0].cc[1].email, "bar@example.com");
assert_eq!(message.personalizations[0].cc[1].name, Some("Peter".to_owned()));
Sourcepub fn bcc<T>(self, email: T) -> MessageBuilder
pub fn bcc<T>(self, email: T) -> MessageBuilder
Appends the given “bcc” email address to the first personalization of the message.
§Examples
let message = MessageBuilder::new().bcc("foo@example.com").finish();
assert_eq!(message.personalizations[0].bcc[0].email, "foo@example.com");
assert_eq!(message.personalizations[0].bcc[0].name, None);
Sourcepub fn bcc_with_name<T, U>(self, email: T, name: U) -> MessageBuilder
pub fn bcc_with_name<T, U>(self, email: T, name: U) -> MessageBuilder
Appends the given “bcc” email address to the first personalization of the message.
§Examples
let message = MessageBuilder::new().bcc_with_name("foo@example.com", "Peter").finish();
assert_eq!(message.personalizations[0].bcc[0].email, "foo@example.com");
assert_eq!(message.personalizations[0].bcc[0].name, Some("Peter".to_owned()));
Sourcepub fn bccs<T>(self, addresses: T) -> MessageBuilderwhere
T: IntoIterator<Item = EmailAddress>,
pub fn bccs<T>(self, addresses: T) -> MessageBuilderwhere
T: IntoIterator<Item = EmailAddress>,
Appends the given “bcc” email addresses to the first personalization of the message.
§Examples
let message = MessageBuilder::new().bccs(
vec![
EmailAddress::new("foo@example.com"),
EmailAddress::new_with_name("bar@example.com", "Peter"),
]).finish();
assert_eq!(message.personalizations[0].bcc[0].email, "foo@example.com");
assert_eq!(message.personalizations[0].bcc[0].name, None);
assert_eq!(message.personalizations[0].bcc[1].email, "bar@example.com");
assert_eq!(message.personalizations[0].bcc[1].name, Some("Peter".to_owned()));
Sourcepub fn subject<T>(self, subject: T) -> MessageBuilder
pub fn subject<T>(self, subject: T) -> MessageBuilder
Sets the subject for the first personalization of the message.
§Examples
let message = MessageBuilder::new().subject("hello world!").finish();
assert_eq!(message.personalizations[0].subject, Some("hello world!".to_owned()));
Sourcepub fn header<T, U>(self, key: T, value: U) -> MessageBuilder
pub fn header<T, U>(self, key: T, value: U) -> MessageBuilder
Appends a header to the first personalization of the message.
§Examples
let message = MessageBuilder::new().header("foo", "bar").finish();
assert_eq!(message.personalizations[0].headers.get("foo").map(String::as_str), Some("bar"));
Sourcepub fn headers<T>(self, headers: T) -> MessageBuilder
pub fn headers<T>(self, headers: T) -> MessageBuilder
Appends multiple headers to the first personalization of the message.
§Examples
let mut headers = HashMap::new();
headers.insert("foo".to_owned(), "bar".to_owned());
headers.insert("bar".to_owned(), "baz".to_owned());
let message = MessageBuilder::new().headers(headers).finish();
assert_eq!(message.personalizations[0].headers.get("foo").map(String::as_str), Some("bar"));
assert_eq!(message.personalizations[0].headers.get("bar").map(String::as_str), Some("baz"));
Sourcepub fn substitution<T, U>(self, key: T, value: U) -> MessageBuilder
pub fn substitution<T, U>(self, key: T, value: U) -> MessageBuilder
Appends a substitution to the first personalization of the message.
§Examples
let message = MessageBuilder::new().substitution("foo", "bar").finish();
assert_eq!(message.personalizations[0].substitutions.get("foo").map(String::as_str), Some("bar"));
Sourcepub fn substitutions<T>(self, substitutions: T) -> MessageBuilder
pub fn substitutions<T>(self, substitutions: T) -> MessageBuilder
Appends multiple substitutions to the first personalization of the message.
§Examples
let mut substitutions = HashMap::new();
substitutions.insert("foo".to_owned(), "bar".to_owned());
substitutions.insert("bar".to_owned(), "baz".to_owned());
let message = MessageBuilder::new().substitutions(substitutions).finish();
assert_eq!(message.personalizations[0].substitutions.get("foo").map(String::as_str), Some("bar"));
assert_eq!(message.personalizations[0].substitutions.get("bar").map(String::as_str), Some("baz"));
Sourcepub fn template_data(self, data: Value) -> MessageBuilder
pub fn template_data(self, data: Value) -> MessageBuilder
Sets the template data for the first personalization of the message.
§Examples
let message = MessageBuilder::new().template_data(json!({ "foo": "bar" })).finish();
assert_eq!(to_string(message.personalizations[0].template_data.as_ref().unwrap()).unwrap(), r#"{"foo":"bar"}"#);
Sourcepub fn custom_arg<T, U>(self, key: T, value: U) -> MessageBuilder
pub fn custom_arg<T, U>(self, key: T, value: U) -> MessageBuilder
Appends a custom argument to the first personalization of the message.
§Examples
let message = MessageBuilder::new().custom_arg("foo", "bar").finish();
assert_eq!(message.personalizations[0].custom_args.get("foo").map(String::as_str), Some("bar"));
Sourcepub fn custom_args<T>(self, args: T) -> MessageBuilder
pub fn custom_args<T>(self, args: T) -> MessageBuilder
Appends multiple custom arguments to the first personalization of the message.
§Examples
let mut args = HashMap::new();
args.insert("foo".to_owned(), "bar".to_owned());
args.insert("bar".to_owned(), "baz".to_owned());
let message = MessageBuilder::new().custom_args(args).finish();
assert_eq!(message.personalizations[0].custom_args.get("foo").map(String::as_str), Some("bar"));
assert_eq!(message.personalizations[0].custom_args.get("bar").map(String::as_str), Some("baz"));
Sourcepub fn send_at(self, timestamp: i64) -> MessageBuilder
pub fn send_at(self, timestamp: i64) -> MessageBuilder
Sets the “send at” timestamp for the first personalization of the message.
Note: This trait uses a Unix timestamp. A handy Unix timestamp converter can be found at unixtimestamp.com/
§Examples
let message = MessageBuilder::new().send_at(1555890183).finish();
assert_eq!(message.personalizations[0].send_at, Some(1555890183));
Sourcepub fn from<T>(self, email: T) -> MessageBuilder
pub fn from<T>(self, email: T) -> MessageBuilder
Sets the “from” email address for the message.
§Examples
let message = MessageBuilder::new().from("foo@example.com").finish();
assert_eq!(message.from.as_ref().unwrap().email, "foo@example.com");
assert_eq!(message.from.as_ref().unwrap().name, None);
Sourcepub fn from_with_name<T, U>(self, email: T, name: U) -> MessageBuilder
pub fn from_with_name<T, U>(self, email: T, name: U) -> MessageBuilder
Sets the “from” email address for the message.
§Examples
let message = MessageBuilder::new().from_with_name("foo@example.com", "Peter").finish();
assert_eq!(message.from.as_ref().unwrap().email, "foo@example.com");
assert_eq!(message.from.as_ref().unwrap().name, Some("Peter".to_owned()));
Sourcepub fn global_subject<T>(self, subject: T) -> MessageBuilder
pub fn global_subject<T>(self, subject: T) -> MessageBuilder
Sets the default global subject for all personalizations of the message.
§Examples
let message = MessageBuilder::new().global_subject("hello world").finish();
assert_eq!(message.subject, Some("hello world".to_owned()));
Sourcepub fn content<T>(self, text: T) -> MessageBuilder
pub fn content<T>(self, text: T) -> MessageBuilder
Adds a text content (with MIME type “text/plain”) to the message.
§Examples
let message = MessageBuilder::new().content("hello world").finish();
assert_eq!(message.contents[0].mime_type, "text/plain");
assert_eq!(message.contents[0].value, "hello world");
Sourcepub fn content_with_type<T, U>(self, content: T, mime_type: U) -> MessageBuilder
pub fn content_with_type<T, U>(self, content: T, mime_type: U) -> MessageBuilder
Adds a content with the given MIME type to the message.
§Examples
let message = MessageBuilder::new().content_with_type("hello world", "text/plain").finish();
assert_eq!(message.contents[0].mime_type, "text/plain");
assert_eq!(message.contents[0].value, "hello world");
Sourcepub fn contents<T>(self, contents: T) -> MessageBuilderwhere
T: IntoIterator<Item = Content>,
pub fn contents<T>(self, contents: T) -> MessageBuilderwhere
T: IntoIterator<Item = Content>,
Adds the given content to the message.
§Examples
let message = MessageBuilder::new()
.contents(
vec![
Content{ mime_type: "text/plain".to_owned(), value: "hello world".to_owned() }
])
.finish();
assert_eq!(message.contents[0].mime_type, "text/plain");
assert_eq!(message.contents[0].value, "hello world");
Sourcepub fn attachment<T, U, V>(
self,
filename: T,
mime_type: U,
content: V,
) -> MessageBuilder
pub fn attachment<T, U, V>( self, filename: T, mime_type: U, content: V, ) -> MessageBuilder
Adds an attachment to the message.
SendGrid expects the
content
argument to be Base 64 encoded. In this example, “hello world” is encoded as “aGVsbG8gd29ybGQ=”
§Examples
let message = MessageBuilder::new().attachment("hello.txt", "text/plain", "aGVsbG8gd29ybGQ=").finish();
assert_eq!(message.attachments[0].filename, "hello.txt");
assert_eq!(message.attachments[0].mime_type, "text/plain");
assert_eq!(message.attachments[0].content, "aGVsbG8gd29ybGQ=");
Sourcepub fn inline_attachment<T, U, V, W>(
self,
filename: T,
mime_type: U,
content: V,
content_id: W,
) -> MessageBuilder
pub fn inline_attachment<T, U, V, W>( self, filename: T, mime_type: U, content: V, content_id: W, ) -> MessageBuilder
Adds an attachment to the message.
SendGrid expects the
content
argument to be Base 64 encoded. In this example, “hello world” is encoded as “aGVsbG8gd29ybGQ=”
§Examples
let message = MessageBuilder::new().inline_attachment("hello.jpg", "image/jpeg", "aGVsbG8gd29ybGQ=", "img_139db99fdb5c3704").finish();
assert_eq!(message.attachments[0].filename, "hello.jpg");
assert_eq!(message.attachments[0].mime_type, "image/jpeg");
assert_eq!(message.attachments[0].content, "aGVsbG8gd29ybGQ=");
assert_eq!(message.attachments[0].disposition, Some("inline".to_owned()));
assert_eq!(message.attachments[0].content_id, Some("img_139db99fdb5c3704".to_owned()));
Sourcepub fn attachments<T>(self, attachments: T) -> MessageBuilderwhere
T: IntoIterator<Item = Attachment>,
pub fn attachments<T>(self, attachments: T) -> MessageBuilderwhere
T: IntoIterator<Item = Attachment>,
Adds multiple attachments to the message.
SendGrid expects the
content
argument to be Base 64 encoded. In this example, “hello world” is encoded as “aGVsbG8gd29ybGQ=”
§Examples
use azure_functions::send_grid::Attachment;
let message = MessageBuilder::new()
.attachments(
vec![
Attachment{ filename: "hello.txt".to_owned(), mime_type: "text/plain".to_owned(), content: "aGVsbG8gd29ybGQ=".to_owned(), ..Default::default() }
])
.finish();
assert_eq!(message.attachments[0].filename, "hello.txt");
assert_eq!(message.attachments[0].mime_type, "text/plain");
assert_eq!(message.attachments[0].content, "aGVsbG8gd29ybGQ=");
Sourcepub fn template_id<T>(self, id: T) -> MessageBuilder
pub fn template_id<T>(self, id: T) -> MessageBuilder
Sets the template id for the message.
§Examples
use azure_functions::send_grid::Attachment;
let message = MessageBuilder::new().template_id("id").finish();
assert_eq!(message.template_id, Some("id".to_owned()));
Sourcepub fn section<T, U>(self, key: T, value: U) -> MessageBuilder
pub fn section<T, U>(self, key: T, value: U) -> MessageBuilder
Appends a section substitution to the message.
§Examples
let message = MessageBuilder::new().section("foo", "bar").finish();
assert_eq!(message.sections.get("foo").map(String::as_str), Some("bar"));
Sourcepub fn sections<T>(self, sections: T) -> MessageBuilder
pub fn sections<T>(self, sections: T) -> MessageBuilder
Appends multiple sections to the message.
§Examples
use std::collections::HashMap;
let mut sections = HashMap::new();
sections.insert("foo".to_owned(), "bar".to_owned());
sections.insert("bar".to_owned(), "baz".to_owned());
let message = MessageBuilder::new().sections(sections).finish();
assert_eq!(message.sections.get("foo").map(String::as_str), Some("bar"));
assert_eq!(message.sections.get("bar").map(String::as_str), Some("baz"));
Sourcepub fn category<T>(self, category: T) -> MessageBuilder
pub fn category<T>(self, category: T) -> MessageBuilder
Appends a category to the message.
§Examples
let message = MessageBuilder::new().category("foo").finish();
assert_eq!(message.categories[0], "foo");
Sourcepub fn categories<T>(self, categories: T) -> MessageBuilderwhere
T: IntoIterator<Item = String>,
pub fn categories<T>(self, categories: T) -> MessageBuilderwhere
T: IntoIterator<Item = String>,
Appends multiple categories to the message.
§Examples
let message = MessageBuilder::new().categories(vec!["foo".to_owned(), "bar".to_owned(), "baz".to_owned()]).finish();
assert_eq!(message.categories[0], "foo");
assert_eq!(message.categories[1], "bar");
assert_eq!(message.categories[2], "baz");
Sourcepub fn global_header<T, U>(self, key: T, value: U) -> MessageBuilder
pub fn global_header<T, U>(self, key: T, value: U) -> MessageBuilder
Appends a global header for all personalizations of the message.
§Examples
let message = MessageBuilder::new().global_header("foo", "bar").finish();
assert_eq!(message.headers.get("foo").map(String::as_str), Some("bar"));
Sourcepub fn global_headers<T>(self, headers: T) -> MessageBuilder
pub fn global_headers<T>(self, headers: T) -> MessageBuilder
Appends multiple global headers for all personalizations of the message.
§Examples
use std::collections::HashMap;
let mut headers = HashMap::new();
headers.insert("foo".to_owned(), "bar".to_owned());
headers.insert("bar".to_owned(), "baz".to_owned());
let message = MessageBuilder::new().global_headers(headers).finish();
assert_eq!(message.headers.get("foo").map(String::as_str), Some("bar"));
assert_eq!(message.headers.get("bar").map(String::as_str), Some("baz"));
Sourcepub fn global_custom_arg<T, U>(self, key: T, value: U) -> MessageBuilder
pub fn global_custom_arg<T, U>(self, key: T, value: U) -> MessageBuilder
Appends a global custom argument for all personalizations of the message.
§Examples
let message = MessageBuilder::new().global_custom_arg("foo", "bar").finish();
assert_eq!(message.custom_args.get("foo").map(String::as_str), Some("bar"));
Sourcepub fn global_custom_args<T>(self, args: T) -> MessageBuilder
pub fn global_custom_args<T>(self, args: T) -> MessageBuilder
Appends multiple global custom arguments for all personalizations of the message.
§Examples
use std::collections::HashMap;
let mut args = HashMap::new();
args.insert("foo".to_owned(), "bar".to_owned());
args.insert("bar".to_owned(), "baz".to_owned());
let message = MessageBuilder::new().global_custom_args(args).finish();
assert_eq!(message.custom_args.get("foo").map(String::as_str), Some("bar"));
assert_eq!(message.custom_args.get("bar").map(String::as_str), Some("baz"));
Sourcepub fn global_send_at(self, timestamp: i64) -> MessageBuilder
pub fn global_send_at(self, timestamp: i64) -> MessageBuilder
Sets the global “send at” timestamp for all personalizations of the message.
Note: This trait uses a Unix timestamp. A handy Unix timestamp converter can be found at unixtimestamp.com
§Examples
let message = MessageBuilder::new().global_send_at(1555890183).finish();
assert_eq!(message.send_at, Some(1555890183));
Sourcepub fn batch_id<T>(self, id: T) -> MessageBuilder
pub fn batch_id<T>(self, id: T) -> MessageBuilder
Sets the batch id for the message.
§Examples
let message = MessageBuilder::new().batch_id("HkJ5yLYULb7Rj8GKSx7u025ouWVlMgAi").finish();
assert_eq!(message.batch_id.unwrap(), "HkJ5yLYULb7Rj8GKSx7u025ouWVlMgAi");
Sourcepub fn finish(self) -> SendGridMessage
pub fn finish(self) -> SendGridMessage
Consumes the builder and returns the SendGrid message.
Trait Implementations§
Source§impl Default for MessageBuilder
impl Default for MessageBuilder
Source§fn default() -> MessageBuilder
fn default() -> MessageBuilder
Auto Trait Implementations§
impl Freeze for MessageBuilder
impl RefUnwindSafe for MessageBuilder
impl Send for MessageBuilder
impl Sync for MessageBuilder
impl Unpin for MessageBuilder
impl UnwindSafe for MessageBuilder
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request