[−][src]Struct azure_functions::send_grid::MessageBuilder
Represents a builder for SendGrid messages.
Methods
impl MessageBuilder
[src]
pub fn new() -> MessageBuilder
[src]
Creates a new message builder.
pub fn to<T>(self, email: T) -> MessageBuilder where
T: Into<String>,
[src]
T: Into<String>,
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);
pub fn to_with_name<T, U>(self, email: T, name: U) -> MessageBuilder where
T: Into<String>,
U: Into<String>,
[src]
T: Into<String>,
U: Into<String>,
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()));
pub fn tos<T>(self, addresses: T) -> MessageBuilder where
T: IntoIterator<Item = EmailAddress>,
[src]
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()));
pub fn cc<T>(self, email: T) -> MessageBuilder where
T: Into<String>,
[src]
T: Into<String>,
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);
pub fn cc_with_name<T, U>(self, email: T, name: U) -> MessageBuilder where
T: Into<String>,
U: Into<String>,
[src]
T: Into<String>,
U: Into<String>,
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()));
pub fn ccs<T>(self, addresses: T) -> MessageBuilder where
T: IntoIterator<Item = EmailAddress>,
[src]
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()));
pub fn bcc<T>(self, email: T) -> MessageBuilder where
T: Into<String>,
[src]
T: Into<String>,
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);
pub fn bcc_with_name<T, U>(self, email: T, name: U) -> MessageBuilder where
T: Into<String>,
U: Into<String>,
[src]
T: Into<String>,
U: Into<String>,
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()));
pub fn bccs<T>(self, addresses: T) -> MessageBuilder where
T: IntoIterator<Item = EmailAddress>,
[src]
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()));
pub fn subject<T>(self, subject: T) -> MessageBuilder where
T: Into<String>,
[src]
T: Into<String>,
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()));
pub fn header<T, U>(self, key: T, value: U) -> MessageBuilder where
T: Into<String>,
U: Into<String>,
[src]
T: Into<String>,
U: Into<String>,
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"));
pub fn headers<T>(self, headers: T) -> MessageBuilder where
T: IntoIterator<Item = (String, String)>,
[src]
T: IntoIterator<Item = (String, String)>,
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"));
pub fn substitution<T, U>(self, key: T, value: U) -> MessageBuilder where
T: Into<String>,
U: Into<String>,
[src]
T: Into<String>,
U: Into<String>,
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"));
pub fn substitutions<T>(self, substitutions: T) -> MessageBuilder where
T: IntoIterator<Item = (String, String)>,
[src]
T: IntoIterator<Item = (String, String)>,
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"));
pub fn template_data(self, data: Value) -> MessageBuilder
[src]
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"}"#);
pub fn custom_arg<T, U>(self, key: T, value: U) -> MessageBuilder where
T: Into<String>,
U: Into<String>,
[src]
T: Into<String>,
U: Into<String>,
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"));
pub fn custom_args<T>(self, args: T) -> MessageBuilder where
T: IntoIterator<Item = (String, String)>,
[src]
T: IntoIterator<Item = (String, String)>,
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"));
pub fn send_at(self, timestamp: i64) -> MessageBuilder
[src]
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));
pub fn from<T>(self, email: T) -> MessageBuilder where
T: Into<String>,
[src]
T: Into<String>,
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);
pub fn from_with_name<T, U>(self, email: T, name: U) -> MessageBuilder where
T: Into<String>,
U: Into<String>,
[src]
T: Into<String>,
U: Into<String>,
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()));
pub fn global_subject<T>(self, subject: T) -> MessageBuilder where
T: Into<String>,
[src]
T: Into<String>,
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()));
pub fn content<T>(self, text: T) -> MessageBuilder where
T: Into<String>,
[src]
T: Into<String>,
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");
pub fn content_with_type<T, U>(self, content: T, mime_type: U) -> MessageBuilder where
T: Into<String>,
U: Into<String>,
[src]
T: Into<String>,
U: Into<String>,
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");
pub fn contents<T>(self, contents: T) -> MessageBuilder where
T: IntoIterator<Item = Content>,
[src]
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");
pub fn attachment<T, U, V>(
self,
filename: T,
mime_type: U,
content: V
) -> MessageBuilder where
T: Into<String>,
U: Into<String>,
V: Into<String>,
[src]
self,
filename: T,
mime_type: U,
content: V
) -> MessageBuilder where
T: Into<String>,
U: Into<String>,
V: Into<String>,
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=");
pub fn inline_attachment<T, U, V, W>(
self,
filename: T,
mime_type: U,
content: V,
content_id: W
) -> MessageBuilder where
T: Into<String>,
U: Into<String>,
V: Into<String>,
W: Into<String>,
[src]
self,
filename: T,
mime_type: U,
content: V,
content_id: W
) -> MessageBuilder where
T: Into<String>,
U: Into<String>,
V: Into<String>,
W: Into<String>,
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()));
pub fn attachments<T>(self, attachments: T) -> MessageBuilder where
T: IntoIterator<Item = Attachment>,
[src]
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=");
pub fn template_id<T>(self, id: T) -> MessageBuilder where
T: Into<String>,
[src]
T: Into<String>,
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()));
pub fn section<T, U>(self, key: T, value: U) -> MessageBuilder where
T: Into<String>,
U: Into<String>,
[src]
T: Into<String>,
U: Into<String>,
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"));
pub fn sections<T>(self, sections: T) -> MessageBuilder where
T: IntoIterator<Item = (String, String)>,
[src]
T: IntoIterator<Item = (String, String)>,
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"));
pub fn category<T>(self, category: T) -> MessageBuilder where
T: Into<String>,
[src]
T: Into<String>,
Appends a category to the message.
Examples
let message = MessageBuilder::new().category("foo").finish(); assert_eq!(message.categories[0], "foo");
pub fn categories<T>(self, categories: T) -> MessageBuilder where
T: IntoIterator<Item = String>,
[src]
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");
pub fn global_header<T, U>(self, key: T, value: U) -> MessageBuilder where
T: Into<String>,
U: Into<String>,
[src]
T: Into<String>,
U: Into<String>,
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"));
pub fn global_headers<T>(self, headers: T) -> MessageBuilder where
T: IntoIterator<Item = (String, String)>,
[src]
T: IntoIterator<Item = (String, String)>,
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"));
pub fn global_custom_arg<T, U>(self, key: T, value: U) -> MessageBuilder where
T: Into<String>,
U: Into<String>,
[src]
T: Into<String>,
U: Into<String>,
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"));
pub fn global_custom_args<T>(self, args: T) -> MessageBuilder where
T: IntoIterator<Item = (String, String)>,
[src]
T: IntoIterator<Item = (String, String)>,
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"));
pub fn global_send_at(self, timestamp: i64) -> MessageBuilder
[src]
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));
pub fn batch_id<T>(self, id: T) -> MessageBuilder where
T: Into<String>,
[src]
T: Into<String>,
Sets the batch id for the message.
Examples
let message = MessageBuilder::new().batch_id("HkJ5yLYULb7Rj8GKSx7u025ouWVlMgAi").finish(); assert_eq!(message.batch_id.unwrap(), "HkJ5yLYULb7Rj8GKSx7u025ouWVlMgAi");
pub fn finish(self) -> SendGridMessage
[src]
Consumes the builder and returns the SendGrid message.
Trait Implementations
impl Default for MessageBuilder
[src]
fn default() -> MessageBuilder
[src]
Auto Trait Implementations
impl Send for MessageBuilder
impl Sync for MessageBuilder
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,