{"id":20747119,"url":"https://github.com/stalwartlabs/mail-builder","last_synced_at":"2025-05-16T03:04:18.639Z","repository":{"id":57636089,"uuid":"450490434","full_name":"stalwartlabs/mail-builder","owner":"stalwartlabs","description":"E-mail builder library for Rust","archived":false,"fork":false,"pushed_at":"2025-03-09T17:35:54.000Z","size":132,"stargazers_count":62,"open_issues_count":7,"forks_count":20,"subscribers_count":6,"default_branch":"main","last_synced_at":"2025-04-08T16:01:36.523Z","etag":null,"topics":["build","create","e-mail","email","generate","mail","mime","rust"],"latest_commit_sha":null,"homepage":"https://docs.rs/mail-builder/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stalwartlabs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSES/Apache-2.0.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"open_collective":"stalwart","github":"stalwartlabs","ko_fi":null,"patreon":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":null}},"created_at":"2022-01-21T12:53:37.000Z","updated_at":"2025-04-06T09:50:07.000Z","dependencies_parsed_at":"2024-05-30T11:47:31.656Z","dependency_job_id":"50505fd6-e686-489f-b7a8-c305c8652b5f","html_url":"https://github.com/stalwartlabs/mail-builder","commit_stats":{"total_commits":40,"total_committers":2,"mean_commits":20.0,"dds":"0.025000000000000022","last_synced_commit":"589dc325508c905c6248d13596a82cd1e89e8315"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stalwartlabs%2Fmail-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stalwartlabs%2Fmail-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stalwartlabs%2Fmail-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stalwartlabs%2Fmail-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stalwartlabs","download_url":"https://codeload.github.com/stalwartlabs/mail-builder/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254459088,"owners_count":22074605,"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":["build","create","e-mail","email","generate","mail","mime","rust"],"created_at":"2024-11-17T08:11:33.632Z","updated_at":"2025-05-16T03:04:13.606Z","avatar_url":"https://github.com/stalwartlabs.png","language":"Rust","funding_links":["https://opencollective.com/stalwart","https://github.com/sponsors/stalwartlabs"],"categories":[],"sub_categories":[],"readme":"# mail-builder\n\n[![crates.io](https://img.shields.io/crates/v/mail-builder)](https://crates.io/crates/mail-builder)\n[![build](https://github.com/stalwartlabs/mail-builder/actions/workflows/rust.yml/badge.svg)](https://github.com/stalwartlabs/mail-builder/actions/workflows/rust.yml)\n[![docs.rs](https://img.shields.io/docsrs/mail-builder)](https://docs.rs/mail-builder)\n[![crates.io](https://img.shields.io/crates/l/mail-builder)](http://www.apache.org/licenses/LICENSE-2.0)\n\n_mail-builder_ is a flexible **e-mail builder library** written in Rust. It includes the following features:\n\n- Generates **e-mail** messages conforming to the Internet Message Format standard (_RFC 5322_).\n- Full **MIME** support (_RFC 2045 - 2049_) with automatic selection of the most optimal encoding for each message body part.\n- **Fast Base64 encoding** based on Chromium's decoder ([the fastest non-SIMD encoder](https://github.com/lemire/fastbase64)).\n- No dependencies (`gethostname` is optional).\n\nPlease note that this library does not support sending or parsing e-mail messages as these functionalities are provided by the crates [`mail-send`](https://crates.io/crates/mail-send) and [`mail-parser`](https://crates.io/crates/mail-parser).\n\n## Usage Example\n\nBuild a simple e-mail message with a text body and one attachment:\n\n```rust\n    // Build a simple text message with a single attachment\n    let eml = MessageBuilder::new()\n        .from((\"John Doe\", \"john@doe.com\"))\n        .to(\"jane@doe.com\")\n        .subject(\"Hello, world!\")\n        .text_body(\"Message contents go here.\")\n        .attachment(\"image/png\", \"image.png\", [1, 2, 3, 4].as_ref())\n        .write_to_string()\n        .unwrap();\n        \n    // Print raw message\n    println!(\"{}\", eml);\n```\n\nMore complex messages with grouped addresses, inline parts and \nmultipart/alternative sections can also be easily built:\n\n```rust\n    // Build a multipart message with text and HTML bodies,\n    // inline parts and attachments.\n    MessageBuilder::new()\n        .from((\"John Doe\", \"john@doe.com\"))\n\n        // To recipients\n        .to(vec![\n            (\"Antoine de Saint-Exupéry\", \"antoine@exupery.com\"),\n            (\"안녕하세요 세계\", \"test@test.com\"),\n            (\"Xin chào\", \"addr@addr.com\"),\n        ])\n\n        // BCC recipients using grouped addresses\n        .bcc(vec![\n            (\n                \"My Group\",\n                vec![\n                    (\"ASCII name\", \"addr1@addr7.com\"),\n                    (\"ハロー・ワールド\", \"addr2@addr6.com\"),\n                    (\"áéíóú\", \"addr3@addr5.com\"),\n                    (\"Γειά σου Κόσμε\", \"addr4@addr4.com\"),\n                ],\n            ),\n            (\n                \"Another Group\",\n                vec![\n                    (\"שלום עולם\", \"addr5@addr3.com\"),\n                    (\"ñandú come ñoquis\", \"addr6@addr2.com\"),\n                    (\"Recipient\", \"addr7@addr1.com\"),\n                ],\n            ),\n        ])\n\n        // Set RFC and custom headers\n        .subject(\"Testing multipart messages\") \n        .in_reply_to(vec![\"message-id-1\", \"message-id-2\"])\n        .header(\"List-Archive\", URL::new(\"http://example.com/archive\"))\n\n        // Set HTML and plain text bodies\n        .text_body(\"This is the text body!\\n\") \n        .html_body(\"\u003cp\u003eHTML body with \u003cimg src=\\\"cid:my-image\\\"/\u003e!\u003c/p\u003e\") \n\n        // Include an embedded image as an inline part\n        .inline(\"image/png\", \"cid:my-image\", [0, 1, 2, 3, 4, 5].as_ref())\n        .attachment(\"text/plain\", \"my fíle.txt\", \"Attachment contents go here.\") \n\n        // Add text and binary attachments\n        .attachment(\n            \"text/plain\",\n            \"ハロー・ワールド\",\n            b\"Binary contents go here.\".as_ref(),\n        )\n\n        // Write the message to a file\n        .write_to(File::create(\"message.eml\").unwrap())\n        .unwrap();\n```\n\nNested MIME body structures can be created using the `body` method:\n\n```rust\n    // Build a nested multipart message\n    MessageBuilder::new()\n        .from(Address::new_address(\"John Doe\".into(), \"john@doe.com\"))\n        .to(Address::new_address(\"Jane Doe\".into(), \"jane@doe.com\"))\n        .subject(\"Nested multipart message\")\n\n        // Define the nested MIME body structure\n        .body(MimePart::new(\n            \"multipart/mixed\",\n            vec![\n                MimePart::new(\"text/plain\", \"Part A contents go here...\").inline(),\n                MimePart::new(\n                    \"multipart/mixed\",\n                    vec![\n                        MimePart::new(\n                            \"multipart/alternative\",\n                            vec![\n                                MimePart::new(\n                                    \"multipart/mixed\",\n                                    vec![\n                                        MimePart::new(\"text/plain\", \"Part B contents go here...\").inline(),\n                                        MimePart::new(\n                                            \"image/jpeg\",\n                                            \"Part C contents go here...\".as_bytes(),\n                                        )\n                                        .inline(),\n                                        MimePart::new(\"text/plain\", \"Part D contents go here...\").inline(),\n                                    ],\n                                ),\n                                MimePart::new(\n                                    \"multipart/related\",\n                                    vec![\n                                        MimePart::new(\"text/html\", \"Part E contents go here...\").inline(),\n                                        MimePart::new(\n                                            \"image/jpeg\",\n                                            \"Part F contents go here...\".as_bytes(),\n                                        ),\n                                    ],\n                                ),\n                            ],\n                        ),\n                        MimePart::new(\"image/jpeg\", \"Part G contents go here...\".as_bytes())\n                            .attachment(\"image_G.jpg\"),\n                        MimePart::new(\n                            \"application/x-excel\",\n                            \"Part H contents go here...\".as_bytes(),\n                        ),\n                        MimePart::new(\n                            \"x-message/rfc822\",\n                            \"Part J contents go here...\".as_bytes(),\n                        ),\n                    ],\n                ),\n                MimePart::new(\"text/plain\", \"Part K contents go here...\").inline(),\n            ],\n        ))\n        \n        // Write the message to a file\n        .write_to(File::create(\"nested-message.eml\").unwrap())\n        .unwrap();\n```\n\n## Testing\n\nTo run the testsuite:\n\n```bash\n $ cargo test --all-features\n```\n\nor, to run the testsuite with MIRI:\n\n```bash\n $ cargo +nightly miri test --all-features\n```\n\n## License\n\nLicensed under either of\n\n * Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)\n * MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)\n\nat your option.\n\n## Copyright\n\nCopyright (C) 2020, Stalwart Labs LLC\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstalwartlabs%2Fmail-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstalwartlabs%2Fmail-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstalwartlabs%2Fmail-builder/lists"}