Expand description
This crate is a wrapper around SendGrid’s v3 API using builder patterns to construct a payload to send. This crate does not have batteries included, does not perform any validations, and makes no assumptions other than what’s specified in SendGrid’s API documentation. To actually call the API, you must use some other mechnism for the HTTP connection (such as the reqwest crate).
Everything stems from Message which you can construct using a
MessageBuilder. When you’re done with the
MessageBuilder call build() to get the underlying Message and to_json() to get the
entire Message output as a JSON string.
§Examples
let api_payload = MessageBuilder::new(
ContactBuilder::new("from@example.com").name("from").build(),
"Subject Line!",
)
.template_id("SENDGRID-TEMPLATE-ID")
// Don't Actually send email. If you want to really send the email, delete the line below
.mail_settings(MailSettingsBuilder::default().sandbox_mode().build())
.personalization(
PersonalizationBuilder::default()
.to(ContactBuilder::new("to@example.com").name("to").build())
.build(),
)
.build()
.to_json();Re-exports§
pub use crate::attachment::AttachmentBuilder;pub use crate::mail_settings::MailSettingsBuilder;pub use crate::message::MessageBuilder;pub use crate::personalization::PersonalizationBuilder;pub use crate::tracking_settings::GaTrackingSettingBuilder;pub use crate::tracking_settings::TrackingSettingsBuilder;
Modules§
Structs§
- Asm
- Type used for SendGrid’s asm fields for managing subscriptions
Use
AsmBuilderto construct this when adding it to aMessage - AsmBuilder
- A builder pattern for constructing
AsmMake sure you callbuild()to consume the builder and retrieve the underylingAsm - Contact
- Struct that holds the data needed for the ‘contact’ section in the SendGrid API.
Use a
ContactBuilderto construct this. - Contact
Builder - Builder pattern for
Contact. Make sure you callbuild()when you’re done to consume the builder and return the underlyingContact. - Content
Contentis the struct used to add content fields on SendGrid’s API This is essentially a key/value store that serializes into the correct format