wangamail_rs/lib.rs
1//! # wangamail-rs
2//!
3//! Send email on behalf of a Microsoft tenant using [Microsoft Graph API](https://learn.microsoft.com/en-us/graph/overview)
4//! and app registration credentials (OAuth2 client credentials flow). Part of the WangaMail family
5//! (`wangamail-rs`, `wangamail-js`, `wangamail-py`, `wangamail-net`).
6//!
7//! ---
8//!
9//! Developed with love by **1nga Solutions** · Logo: <https://www.1nga.com/logo.svg>
10//!
11//! ## Features
12//!
13//! - **Default:** Build a [`GraphMailClient`] and send mail with [`send_mail`](GraphMailClient::send_mail).
14//! - **`mcp`:** Optional [Model Context Protocol](https://modelcontextprotocol.io/) server that exposes a
15//! **send_email** tool for AI assistants (Cursor, Claude Desktop, etc.). See the [`mcp`] module.
16//!
17//! ## Setup
18//!
19//! 1. Register an application in [Azure Portal](https://portal.azure.com) → Microsoft Entra ID → App registrations.
20//! 2. Create a client secret for the app.
21//! 3. Under **API permissions**, add application permission **Mail.Send** for Microsoft Graph and grant admin consent.
22//! 4. To send as a specific user, that user must have a mailbox in Exchange Online; the app sends as the user identified by `from_user` (user id or userPrincipalName).
23//!
24//! ## Example
25//!
26//! ```no_run
27//! use wangamail_rs::{GraphMailClient, Message, BodyType, Recipient, SendMailRequest};
28//!
29//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
30//! let client = GraphMailClient::builder()
31//! .tenant_id("your-tenant-id")
32//! .client_id("your-client-id")
33//! .client_secret("your-client-secret")
34//! .build()?;
35//!
36//! let request = SendMailRequest::new(Message {
37//! subject: "Hello from Graph".to_string(),
38//! body: wangamail_rs::MessageBody {
39//! content_type: BodyType::Text,
40//! content: "This email was sent via Microsoft Graph.".to_string(),
41//! },
42//! to_recipients: vec![
43//! Recipient::new("recipient@example.com"),
44//! ],
45//! ..Default::default()
46//! });
47//!
48//! client.send_mail("user@yourtenant.onmicrosoft.com", request).await?;
49//! # Ok(())
50//! # }
51//! ```
52//!
53//! ## Modules
54//!
55//! - **[`mcp`]** (optional, feature `mcp`): MCP server and **send_email** tool for AI tool use.
56
57#![warn(missing_docs)]
58
59mod auth;
60mod client;
61mod error;
62mod graph;
63
64#[cfg(feature = "mcp")]
65pub mod mcp;
66
67pub use client::{GraphMailClient, GraphMailClientBuilder};
68pub use error::{Error, Result};
69pub use graph::{
70 BodyType, EmailAddress, FileAttachment, Message, MessageBody, Recipient, SendMailRequest,
71};