{"id":27443832,"url":"https://github.com/leoborai/mailjet-rs","last_synced_at":"2025-04-15T02:50:29.238Z","repository":{"id":39637001,"uuid":"291890189","full_name":"LeoBorai/mailjet-rs","owner":"LeoBorai","description":"Mailjet API wrapper for Rust","archived":false,"fork":false,"pushed_at":"2023-01-09T09:02:54.000Z","size":371,"stargazers_count":15,"open_issues_count":1,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-14T07:09:11.140Z","etag":null,"topics":["api","api-client","email","mailjet","rust","send"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/mailjet-rs","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LeoBorai.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-09-01T03:52:33.000Z","updated_at":"2023-09-08T18:11:56.000Z","dependencies_parsed_at":"2023-02-08T09:31:30.611Z","dependency_job_id":null,"html_url":"https://github.com/LeoBorai/mailjet-rs","commit_stats":null,"previous_names":["leoborai/mailjet-rs","estebanborai/mailjet-rs"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeoBorai%2Fmailjet-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeoBorai%2Fmailjet-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeoBorai%2Fmailjet-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LeoBorai%2Fmailjet-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LeoBorai","download_url":"https://codeload.github.com/LeoBorai/mailjet-rs/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248997087,"owners_count":21195797,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","api-client","email","mailjet","rust","send"],"created_at":"2025-04-15T02:50:28.424Z","updated_at":"2025-04-15T02:50:29.232Z","avatar_url":"https://github.com/LeoBorai.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv\u003e\n  \u003cdiv align=\"center\" style=\"display: block; text-align: center;\"\u003e\n    \u003cimg src=\"https://raw.githubusercontent.com/EstebanBorai/mailjet-rs/main/assets/mailjet-rs.png\" height=\"120\" width=\"120\" /\u003e\n  \u003c/div\u003e\n  \u003ch1 align=\"center\"\u003emailjet-rs\u003c/h1\u003e\n  \u003ch4 align=\"center\"\u003eMailjet API wrapper for Rust\u003c/h4\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n  ![MIT License](https://img.shields.io/badge/license-MIT-007EC7.svg?style=flat-square)\n  [![Crates.io](https://img.shields.io/crates/v/mailjet-rs.svg)](https://crates.io/crates/mailjet-rs)\n  [![Documentation](https://docs.rs/mailjet-rs/badge.svg)](https://docs.rs/mailjet-rs)\n\n\u003c/div\u003e\n\n## Overview\n\nThis crate contains an unofficial wrapper for the Mailjet API.\n\nThe official resources are available in the [Mailjet Developer Guides](https://dev.mailjet.com/email/guides/) webiste.\n\nThe official [Mailjet Organization in GitHub](https://github.com/mailjet) provides wrappers\nfor other programming languages such as Go, PHP, JavaScript (NodeJS), Ruby and more.\n\n## Contents\n\n- [Installation](#installation)\n- [Client](#client)\n  - [Authentication](#authentication)\n  - [API Version](#api-version)\n- [Send Messages](#send-messages)\n  - [Examples Requirements](#examples-requirements)\n  - [Consuming the API Wrapper](#consuming-the-api-wrapper)\n  - [Basic Message](#basic-message)\n  - [Send to multiple recipients](#send-to-multiple-recipients)\n  - [Using `To`, `Cc` and `Bcc` instead of `Recipients`](#using-to-cc-and-bcc-instead-of-recipients)\n  - [Send Inline Attachments](#send-inline-attachments)\n  - [Full Featured Example on v3](#full-featured-example-on-v3)\n\n### Installation\n\n```toml\nmailjet-rs = \"0.2.0\"\n\n# Used by `Hyper` which is the HTTP request solution behind the Client\ntokio = { version = \"1\", features = [\"full\"] }\n```\n\n### Client\n\nThe `Client` struct performs API related tasks such as handling authentication and defning the API version\nthat must be used for every request.\n\n### Authentication\n\nMailjet's Email API uses the API keys provided by Mailjet for your account [here](https://app.mailjet.com/account/api_keys).\n\nThese are used to create an instance of the `Client` as follows:\n\n```rust\nlet client = Client::new(\n    SendAPIVersion::V3,\n    \"public_key\",\n    \"private_key\",\n);\n```\n\n### API Version\n\nMailjet's API has 3 versions available at the moment, the following table describes each version and its\nsupport in this crate\n\nVersion | Name | Supported\n--- | --- | ---\nv3 | The Email API | ✔️\nv3.1 | Email Send API v3.1 (Latest Version) | ❌ (Early Development)\nv4 | SMS API | ❌ (TBD)\n\n\u003e As you can see at the moment this crate supports only the version 3 of the Email API. Support for the version 3.1 is in early development\n\nThe version of the API to use is provided to the `Client` using the `SendAPIVersion` enum.\n\n### Send Messages\n\nTo send a `Message` you must create a `Client` instance, then define `Recipients` and finally build your `Message`.\n\nThe `Client`'s method `send` receives a `Payload` trait implementator, this trait is implemented by `Message` and every struct which is\nsent to the Mailjet's API throught the `Client`.\n\nA call to `send` will return a `Future` which wraps a `Result\u003cMailjetResponse, MailjetError\u003e`.\n\n### Examples Requirements\n\nTo run any of the following examples you must have a public and private key for Mailjet (a free plan is available to consume the API)\nand also install the tokio runtime.\n\n```toml\nmailjet-rs = \"0.2.0\"\n\n# Used by `Hyper` which is the HTTP request solution behind the Client\ntokio = { version = \"1\", features = [\"full\"] }\n```\n\n### Consuming the API Wrapper\n\nTheres two ways to consume this wrapper, either by using the methods provided by the `Message` struct or not to using these\nmethods.\n\nAll of the fields of the `Message` struct are public, this is because sometimes its a bit of verbose/tedious to build\na simple struct by calling multiple methods.\n\nThe methods provided are meant to validate the fields of the `Message` struct with the API specificiations but you are free\nto provide values to these fields.\n\n### Basic Message\n\n**mailjet-rs** makes use of the Tokio runtime to perform asynchronous operations,\nHyper is being used undet the hood to perform HTTP requests to the Mailjet API.\n\nHere a `Message` is created and sent to the `Recipient` defined.\nThis message neither contains HTML or is consuming a template, instead this `Message` contains\nraw text.\n\n```rust\nuse mailjet_rs::common::Recipient;\nuse mailjet_rs::v3::Message;\nuse mailjet_rs::{Client, SendAPIVersion};\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error + Send + Sync\u003e\u003e {\n    // Create an instance of the Mailjet API client\n    // used to send the `Message` and also define your API\n    // credentials\n    let client = Client::new(\n        SendAPIVersion::V3,\n        \"public_key\",\n        \"private_key\",\n    );\n\n    // Create your a `Message` instance with the minimum required values\n    let mut message = Message::new(\n        \"mailjet_sender@company.com\",\n        \"Mailjet Rust\",\n        Some(\"Your email flight plan!\".to_string()),\n        Some(\"Dear passenger, welcome to Mailjet! May the delivery force be with you!\".to_string())\n    );\n\n    message.push_recipient(Recipient::new(\"receiver@company.com\"));\n\n    // Finally send the message using the `Client`\n    let response = client.send(message).await;\n\n    // Do something with the response from Mailjet\n    // Ok(Response { sent: [Sent { email: \"your_receiver@company.com\", message_id: 000, message_uuid: \"message-uuid\" }] })\n    println!(\"{:?}\", response);\n\n    Ok(())\n}\n```\n\n### Send to multiple recipients\n\n```rust\nuse mailjet_rs::common::Recipient;\nuse mailjet_rs::v3::Message;\nuse mailjet_rs::{Client, SendAPIVersion};\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error + Send + Sync\u003e\u003e {\n    let client = Client::new(\n        SendAPIVersion::V3,\n        \"public_key\",\n        \"private_key\",\n    );\n\n    let mut message = Message::new(\n        \"mailjet_sender@company.com\",\n        \"Mailjet Rust\",\n        Some(\"Your email flight plan!\".to_string()),\n        Some(\"Dear passenger, welcome to Mailjet! May the delivery force be with you!\".to_string())\n    );\n\n    let recipients = vec![\n        Recipient::new(\"receiver1@company.com\"),\n        Recipient::new(\"receiver2@company.com\"),\n        Recipient::new(\"receiver3@company.com\"),\n    ];\n\n    message.push_many_recipients(recipients);\n\n    let response = client.send(message).await;\n\n    println!(\"{:?}\", response);\n\n    Ok(())\n}\n```\n\n### Using `To`, `Cc` and `Bcc` instead of `Recipients`\n\n\u003e Note: If a recipient does not exist in any of your contact list it will be created from scratch, keep that in mind if you are planning on sending a welcome email and then you're trying to add the email to a list as the contact effectively exists already. [Mailjet's API Documentation](https://dev.mailjet.com/email/guides/send-api-V3/#send-a-basic-email)\n\n```rust\nuse mailjet_rs::common::Recipient;\nuse mailjet_rs::v3::Message;\nuse mailjet_rs::{Client, SendAPIVersion};\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error + Send + Sync\u003e\u003e {\n    let client = Client::new(\n        SendAPIVersion::V3,\n        \"public_key\",\n        \"private_key\",\n    );\n\n    let mut message = Message::new(\n        \"mailjet_sender@company.com\",\n        \"Mailjet Rust\",\n        Some(\"Your email flight plan!\".to_string()),\n        Some(\"Dear passenger, welcome to Mailjet! May the delivery force be with you!\".to_string())\n    );\n\n    message.set_receivers(\n        vec![\n            Recipient::new(\"bar@foo.com\"),\n        ],\n        Some(vec![\n            Recipient::new(\"bee@foo.com\"),\n        ]),\n        None\n    );\n\n    let response = client.send(message).await;\n\n    println!(\"{:?}\", response);\n\n    Ok(())\n}\n```\n\n### Send Inline Attachments\n\n```rust\nuse mailjet_rs::common::Recipient;\nuse mailjet_rs::v3::{Message, Attachment};\nuse mailjet_rs::{Client, SendAPIVersion};\n\n/// Base64 representation of the Mailjet logo found in the Mailjet SendAPI V3 docs\nconst MAILJET_LOGO_BASE64: \u0026str = \"iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAB3RJTUUH4wIIChcxurq5eQAAAAd0RVh0QXV0aG9yAKmuzEgAAAAMdEVYdERlc2NyaXB0aW9uABMJISMAAAAKdEVYdENvcHlyaWdodACsD8w6AAAADnRFWHRDcmVhdGlvbiB0aW1lADX3DwkAAAAJdEVYdFNvZnR3YXJlAF1w/zoAAAALdEVYdERpc2NsYWltZXIAt8C0jwAAAAh0RVh0V2FybmluZwDAG+aHAAAAB3RFWHRTb3VyY2UA9f+D6wAAAAh0RVh0Q29tbWVudAD2zJa/AAAABnRFWHRUaXRsZQCo7tInAAABV0lEQVQokaXSPWtTYRTA8d9N7k1zm6a+RG2x+FItgpu66uDQxbFurrr5OQQHR9FZnARB3PwSFqooddAStCBoqmLtS9omx+ESUXuDon94tnP+5+1JYm057GyQjZFP+l+S6G2FzlNe3WHtHc2TNI8zOlUUGLxsD1kDyR+EEQE2P/L8Jm/uk6RUc6oZaYM0JxtnpEX9AGPTtM6w7yzVEb61EaSNn4QD3j5m4QabH6hkVFLSUeqHyCeot0ib6BdNVGscPM/hWWr7S4Tw9TUvbpFUitHTnF6XrS+sL7O6VBSausT0FZonSkb+nZUFFm+z8Z5up5Btr1Lby7E5Zq4yPrMrLR263ZV52g+LvfW3iy6PXubUNVrnhqYNF3bmiZ1i1MmLnL7OxIWh4T+IMpYeRNyrRzyZjWg/ioh+aVgZu4WfXxaixbsRve5fiwb8epTo8+kZjSPFf/sHvgNC0/mbjJbxPAAAAABJRU5ErkJggg==\";\n\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error + Send + Sync\u003e\u003e {\n    let client = Client::new(\n        SendAPIVersion::V3,\n        \"public_key\",\n        \"private_key\",\n    );\n\n    let mut message = Message::new(\n        \"mailjet_sender@company.com\",\n        \"Mailjet Rust\",\n        Some(\"Your email flight plan!\".to_string()),\n        Some(\"Dear passenger, welcome to Mailjet! May the delivery force be with you!\".to_string())\n    );\n\n    message.set_receivers(\n        vec![\n            Recipient::new(\"bar@foo.com\"),\n        ],\n        Some(vec![\n            Recipient::new(\"bee@foo.com\"),\n        ]),\n        None\n    );\n\n    let mailjet_logo = Attachment::new(\n        \"image/png\", \n        \"logo.png\", \n        MAILJET_LOGO_BASE64);\n\n    message.attach_inline(mailjet_logo);\n\n    message.html_part = Some(\"\u003ch3\u003eDear [[var:name]] [[var:last]], welcome to \u003cimg src=\\\"cid:logo.png\\\"\u003e \u003ca href=\\\"https://www.mailjet.com/\\\"\u003eMailjet\u003c/a\u003e!\u003cbr /\u003eMay the delivery force be with you!\".to_string());\n\n\n    let response = client.send(message).await;\n\n    println!(\"{:?}\", response);\n\n    Ok(())\n}\n```\n\n### Full Featured Example on v3\n\nThe following is an example using the Mailjet's Send API v3 where the following\nfeatures are covered:\n\n- Attach inline images\n- Attach files\n- Use template variables\n\n```rust\nuse mailjet_rs::common::Recipient;\nuse mailjet_rs::v3::{Message, Attachment};\nuse mailjet_rs::{Client, SendAPIVersion};\nuse mailjet_rs::{Map, Value};\n\n/// Base64 representation of the Mailjet logo found in the Mailjet SendAPI V3 docs\nconst MAILJET_LOGO_BASE64: \u0026str = \"iVBORw0KGgoAAAANSUhEUgAAABQAAAALCAYAAAB/Ca1DAAAACXBIWXMAAA7EAAAOxAGVKw4bAAAAB3RJTUUH4wIIChcxurq5eQAAAAd0RVh0QXV0aG9yAKmuzEgAAAAMdEVYdERlc2NyaXB0aW9uABMJISMAAAAKdEVYdENvcHlyaWdodACsD8w6AAAADnRFWHRDcmVhdGlvbiB0aW1lADX3DwkAAAAJdEVYdFNvZnR3YXJlAF1w/zoAAAALdEVYdERpc2NsYWltZXIAt8C0jwAAAAh0RVh0V2FybmluZwDAG+aHAAAAB3RFWHRTb3VyY2UA9f+D6wAAAAh0RVh0Q29tbWVudAD2zJa/AAAABnRFWHRUaXRsZQCo7tInAAABV0lEQVQokaXSPWtTYRTA8d9N7k1zm6a+RG2x+FItgpu66uDQxbFurrr5OQQHR9FZnARB3PwSFqooddAStCBoqmLtS9omx+ESUXuDon94tnP+5+1JYm057GyQjZFP+l+S6G2FzlNe3WHtHc2TNI8zOlUUGLxsD1kDyR+EEQE2P/L8Jm/uk6RUc6oZaYM0JxtnpEX9AGPTtM6w7yzVEb61EaSNn4QD3j5m4QabH6hkVFLSUeqHyCeot0ib6BdNVGscPM/hWWr7S4Tw9TUvbpFUitHTnF6XrS+sL7O6VBSausT0FZonSkb+nZUFFm+z8Z5up5Btr1Lby7E5Zq4yPrMrLR263ZV52g+LvfW3iy6PXubUNVrnhqYNF3bmiZ1i1MmLnL7OxIWh4T+IMpYeRNyrRzyZjWg/ioh+aVgZu4WfXxaixbsRve5fiwb8epTo8+kZjSPFf/sHvgNC0/mbjJbxPAAAAABJRU5ErkJggg==\";\n\n#[tokio::main]\nasync fn main() -\u003e Result\u003c(), Box\u003cdyn std::error::Error + Send + Sync\u003e\u003e {\n\n    // Create an instance of the Mailjet API client\n    // used to send the `Message` and also define your API\n    // credentials\n    let client = Client::new(\n        SendAPIVersion::V3,\n        \"public_key\",\n        \"private_key\",\n    );\n\n    // Create your a `Message` instance with the minimum required values\n    let mut message = Message::new(\n        \"mailjet_sender@company.com\",\n        \"Mailjet Rust\",\n        Some(\"Your email flight plan!\".to_string()),\n        Some(\"Dear passenger, welcome to Mailjet! May the delivery force be with you!\".to_string())\n    );\n\n    message.push_recipient(Recipient::new(\"receiver@company.com\"));\n\n    // Set some HTML for your email\n    // \n    // Note that here we are using `cid:logo.png` as the src value for our image\n    // this is using the `inline_attachment` with `filename` \"logo.png\" as the\n    // image source\n    message.html_part = Some(\"\u003ch3\u003eDear [[var:name]] [[var:last]], welcome to \u003cimg src=\\\"cid:logo.png\\\"\u003e \u003ca href=\\\"https://www.mailjet.com/\\\"\u003eMailjet\u003c/a\u003e!\u003cbr /\u003eMay the delivery force be with you!\".to_string());\n\n    // Attach inline files providing its base64 representation\n    // content-type and a name.\n    // The name of the file can be used to reference this file in your HTML content\n    let mailjet_logo_inline = Attachment::new(\n      \"image/png\", \n      \"logo.png\", \n      MAILJET_LOGO_BASE64);\n\n    // Attach the `Attachment` as an Inline Attachment\n    // this function can also be used to attach common Attachments\n    message.attach_inline(mailjet_logo_inline);\n\n    // Creates a txt file Attachment\n    let txt_file_attachment = Attachment::new(\n      \"text/plain\", \n      \"test.txt\", \n      \"VGhpcyBpcyB5b3VyIGF0dGFjaGVkIGZpbGUhISEK\");\n\n    // Attaches the TXT file as an email Attachment\n    message.attach(txt_file_attachment);\n\n    // Provide variables for your template\n    // `Map` and `Value` are reexported from\n    // `serde_json`\n    let mut vars = Map::new();\n\n    vars.insert(String::from(\"name\"), Value::from(\"Foo\"));\n    vars.insert(String::from(\"last\"), Value::from(\"Bar\"));\n\n    message.vars = Some(vars);\n\n    // Finally send the message using the `Client`\n    let response = client.send(message).await;\n\n    // Do something with the response from Mailjet\n    // Ok(Response { sent: [Sent { email: \"your_receiver@company.com\", message_id: 000, message_uuid: \"message-uuid\" }] })\n    println!(\"{:?}\", response);\n\n    Ok(())\n}\n```\n\n## Release\n\nTo release a new version you must tag with git and push to the `main` branch.\n\n```bash\ngit tag -a v0.1.0 -m \"First Release\"\ngit push origin main --follow-tags\n```\n\n## Contribute\n\nFeel free to contribute!\n\n## License\n\nThis project is licensed under the MIT License to match the same licensing as Mailjet's official wrappers\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleoborai%2Fmailjet-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fleoborai%2Fmailjet-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fleoborai%2Fmailjet-rs/lists"}