2 releases
0.1.1 | Jan 28, 2019 |
---|---|
0.1.0 | Jan 28, 2019 |
#282 in Email
138 downloads per month
45KB
547 lines
sendgrid-rs
Wrapper crate for SendGrid's v3 JSON API
Use builder patterns to construct the correct JSON to call SendGrid's v3 API. This crate is a WIP, but right now includes everything needed to generate a request to send email.
lib.rs
:
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();
Dependencies
~0.7–1.6MB
~34K SLoC