[![Building](https://github.com/nevermille/rust-mailjet/actions/workflows/test-stable.yml/badge.svg)](https://github.com/nevermille/rust-mailjet/actions/workflows/test-stable.yml) # Unoficial wrapper for Mailjet API Rust wrapper for Mailjet's API Mailjet is a service provider for sending emails and SMS, visit for more information. **WARNING**: This wrapper is not official, Mailjet won't provide any support for it. # Getting Started The first step is to instantiate a Mailjet structure with your API keys: ```rust use mailjet_api_wrapper::Mailjet; let mailjet = Mailjet::from_api_keys("your_api_key", "your_api_secret"); ``` Now, each route in the API correspond to a function in your mailjet object, for example with message route: ```rust use mailjet_api_wrapper::Mailjet; use mailjet_api_wrapper::requests::MessageRequest; let mailjet = Mailjet::from_api_keys("your_api_key", "your_api_secret"); let res = mailjet.message(&MessageRequest::default()).unwrap_or_default(); ``` Those functions have an explicit name, you'll find them easily in the complete documentation or directly in your IDE. In the case of multiple routes having the same name, the functions will be prefixed by an action verb like `_create` or `_update`. # Simple routes Those routes only have a few variables in the url and have no parameters, they appear in the API reference like `/message/{message_ID}`. In this case, the function name will be suffixed by `_from_*`. ```rust use mailjet_api_wrapper::Mailjet; use mailjet_api_wrapper::requests::MessageRequest; let mailjet = Mailjet::from_api_keys("your_api_key", "your_api_secret"); let res = mailjet.message_from_id(123456789).unwrap_or_default(); ``` # Complex routes Those routes have parameters to append at the end of the URL or a JSON body like `/message` or `/send`. In this case, you need to build a request object before passing it to the function. You can find them in the `requests` module. ```rust use mailjet_api_wrapper::Mailjet; use mailjet_api_wrapper::requests::MessageInformationRequest; let mailjet = Mailjet::from_api_keys("your_api_key", "your_api_secret"); let request = MessageInformationRequest { campaign_id: Some(544678796), // Corresponds to parameter CampaignID ..Default::default() }; let res = mailjet.message_information(&request).unwrap_or_default(); ``` # Hybrid routes Those routes have both a URL variable and a body/URL parameters like `/contact` (PUT), in this case, the function takes 2+ arguments, the first ones are the URL variables and the last one, the request object ```rust use mailjet_api_wrapper::Mailjet; use mailjet_api_wrapper::requests::ContactRequest; use mailjet_api_wrapper::data::ContactIdentifier; let mailjet = Mailjet::from_api_keys("your_api_key", "your_api_secret"); let request = ContactRequest { name: Some("New Name".to_string()), // Corresponds to parameter CampaignID ..Default::default() }; let response = mailjet .contact_update( &ContactIdentifier::ContactEmail("passenger1@mailjet.com".to_string()), &request, ) .unwrap_or_default(); ``` # Response Every route returning a JSON will build a response object. You can find them in the `responses` module. ```rust use mailjet_api_wrapper::Mailjet; use mailjet_api_wrapper::requests::MessageRequest; let mailjet = Mailjet::from_api_keys("your_api_key", "your_api_secret"); let res = mailjet.message(&MessageRequest::default()).unwrap_or_default(); let obj = res.object.unwrap_or_default(); let count = obj.count; // Corresponds to Count response field let data = obj.data; // Corresponds to Data response field ``` # The data structures The request and response structures are the same as mailjet's JSONs and parameters' names with PascalCase field names converted into snake_case format as asked by rust. Every JSON request and response is serializable/deserializable with serde, so you can easily build objects with JSON formats with serde_json. For complete information on JSON structures and parameters, go read # Example: send a basic email ```rust use mailjet_api_wrapper::{ data::{EmailAddress, Message}, requests::SendRequest, Mailjet, }; // Create mailjet client let mailjet = Mailjet::from_api_keys("your_key", "your_secret"); // Create recipients let to = EmailAddress::from_email("passenger1@mailjet.com"); let from = EmailAddress::from_email_and_name("pilot@mailjet.com", "Mailjet Pilot"); // Create message let mut message = Message::default(); message.to.push(to); message.from = from; message.html_part = "

Dear passenger 1, welcome to Mailjet!


May the delivery force be with you!".to_string(); message.text_part = "Dear passenger 1, welcome to Mailjet! May the delivery force be with you!".to_string(); message.subject = "Your email flight plan!".to_string(); // Create send request let mut send_request = SendRequest::default(); send_request.sandbox_mode = Some(true); // You can remove this when sending for real send_request.messages.push(message); // Send emails let response = mailjet.send(&send_request).unwrap_or_default(); ``` # Features | Categories | Features | Actions | |------------------------------|-------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | Send Emails | - | ✅ Send an email message via Send API v3.1
❌ Send an email message via Send API v3 | | Messages | - | ✅ Get detailed information on all processed messages
✅ Get detailed information on a specific processed message
✅ Get the event history for a specific message
✅ Retrieve sending / size / spam information about all messages
✅ Retrieve sending / size / spam information about a specific message ID | | Contact | Contact | ✅ Create a new contact
✅ Get a list of all contacts
✅ Get a specific contact
✅ Update a specific contact
✅ Delete a contact (GDPR) | | Contact | Contact List | ✅ Create a new contact list
✅ Retrieve general details for all contact lists
✅ Retrieve information on a specific contact list
✅ Update a specific contact list
✅ Delete a contact list | | Contact | Bulk Contact Management | ❌ Add, remove or unsubscribe a list of contacts to/from a selection of contact lists
❌ Add, unsubscribe or remove the contacts present in a list to / from another list
❌ Add, remove or unsubscribe a list of contacts to/from a specific contact list
❌ Use an uploaded CSV list of contacts to manage their presence and subscription status in a contact list
❌ Monitor a submitted upload / update request for multiple contacts
❌ Monitor a submitted upload / update request for contacts from one list to another
❌ Monitor a submitted upload / update request for multiple contacts into a specific contact list
❌ View the status of a CSV import job
❌ Update or abort a contact CSV import job in progress | | Contact | Contact Properties | ❌ Create a new contact property
❌ Get information on all contacts and the property values associated with them
❌ Get the contact property values relating to a specific contact
❌ Get information on all contact properties
❌ Get information on a specific contact property
❌ Update the contact property values relating to a specific contact
❌ Update the settings of an existing contact property
❌ Delete all contact property values relating to a specific contact
❌ Delete an existing contact property | | Contact | Subscriptions | ❌ Add, remove or unsubscribe a contact to/from a selection of contact lists
❌ Manage a single contact subscription to a specific contact list
❌ Create a new list recipient
❌ Get all contact lists for a specific contact
❌ Get info on all signup requests via a subscription widget
❌ Get info on a specific signup request via a subscription widget
❌ Get details on all list recipients
❌ Get details for a specific list recipient
❌ Update the subscription status of a list recipient
❌ Delete a list recipient | | Contact | Verifications | ❌ Start a contact list verification
❌ Retrieves the current state of the contact list verification job | | Campaigns | Drafts | ❌ Create a new campaign draft
❌ Manage the content of your campaign draft email
❌ Get all campaign drafts and their configuration
❌ Get a specific campaign draft and its configuration details
❌ Retrieve the content of your campaign draft email
❌ Update an existing campaign draft
❌ Retrieve the sending schedule of a campaign draft
❌ Schedule the sending of a campaign draft
❌ Update the sending schedule of a campaign draft
❌ Cancel the scheduled sending of a campaign draft
❌ Send a campaign draft immediately
❌ View the sending status of a campaign draft
❌ Send a test email for a specified campaign draft | | Campaigns | Sent Campaigns | ❌ Get detailed information about all campaigns
❌ Get detailed information about a specific campaign
❌ Delete a campaign or mark it as starred | | Segmentation | - | ❌ Create a new contact segmentation formula
❌ Get a list of all existing segments
❌ Get an existing contact segmentation formula
❌ Update an existing contact segmentation formula
❌ Delete an existing contact segmentation formula | | Templates | - | ❌ Create an email template
❌ Create the contents of an email template
❌ Get all email templates
❌ Retrieve the configuration settings for a specific template
❌ Get the contents of an email template
❌ Update the configuration settings of an email template
❌ Update the contents of an email template
❌ Delete an email template | | Statistics | - | ❌ Get general details and stats for all drafts, AB Testing objects and/or sent campaigns
❌ Get information about a specific draft, AB Testing object or sent campaign
❌ Get aggregated statistics, grouped by contact
❌ Get aggregated statistics for a specific contact
❌ Retrieve aggregated open and click statistics, grouped by recipient country
❌ Get aggregated statistics, grouped by list recipient
❌ Get aggregated statistics for a specific list recipient
❌ Get message-based or event-based aggregated statistics for a specific campaign, contact list, API Key or sender email address
❌ Get aggregated statistics for all clicked links in a campaign
❌ Retrieve statistics, aggregated by recipient's Email Service Provider (ESP)
❌ Get aggregated statistics for all clicked links
❌ Get open or click counts, grouped by web browser / email client | | Message Events | - | ❌ Get a list of all bounce events
❌ Get details for a specific bounce event
❌ Get a list of all click events
❌ Get a list of all open events
❌ Retrieve open event details for a specific message | | Webhook | - | ❌ Add a new callback URL
❌ Get a list of all callback URLs
❌ Get the configuration of a specific callback URL
❌ Update the configuration of an existing callback URL
❌ Delete an existing callback URL | | Parse | - | ❌ Create a new parseroute instance
❌ Get a list of all parseroute instances
❌ Get the configuration details for a specific parseroute resource
❌ Update an existing parseroute instance
❌ Delete an existing parseroute instance | | Sender Addresses and Domains | Sender | ❌ Create a new sender email address or domain
❌ Get a list of all existing sender email addresses and domains
❌ Retrieve details on a specific sender email address or domain
❌ Update an existing sender email address or domain
❌ Delete an existing sender email address or domain
❌ Validate a sender email address or domain | | Sender Addresses and Domains | Metasender | ❌ Create a new metasender
❌ Get a list of all metasenders
❌ Get a specific metasender
❌ Update and existing metasender | | Sender Addresses and Domains | DNS | ❌ Get the SPF and DKIM settings for all sender domains
❌ Get the SPF and DKIM settings for a specific sender domain
❌ Perform a DNS validation of a sender domain | | Settings | API Key Configuration | ❌ Create a new sub-account API Key
❌ Get all API Keys and their configuration settings
❌ Get the configuration settings of a specific API Key
❌ Update an existing API Key | | Settings | Account Settings | ❌ Retrieve your profile information
❌ Get general information on your user settings and activity
❌ Update your profile information
❌ Update the settings of your User ID | | Send SMS | - | ❌ Send an SMS Message | | SMS Messages | - | ❌ Request an export of SMS messages
❌ Retrieve a list of SMS messages
❌ Retrieve SMS messages count
❌ Retrieve an export request result
❌ Retrieve a single SMS message |