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//! ## Features
8//!
9//! - **Default:** Build a [`GraphMailClient`] and send mail with [`send_mail`](GraphMailClient::send_mail).
10//! - **`mcp`:** Optional [Model Context Protocol](https://modelcontextprotocol.io/) server that exposes a
11//! **send_email** tool for AI assistants (Cursor, Claude Desktop, etc.). See the [`mcp`] module.
12//!
13//! ## Setup
14//!
15//! 1. Register an application in [Azure Portal](https://portal.azure.com) → Microsoft Entra ID → App registrations.
16//! 2. Create a client secret for the app.
17//! 3. Under **API permissions**, add application permission **Mail.Send** for Microsoft Graph and grant admin consent.
18//! 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).
19//!
20//! ## Example
21//!
22//! ```no_run
23//! use wangamail_rs::{GraphMailClient, Message, BodyType, Recipient, SendMailRequest};
24//!
25//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
26//! let client = GraphMailClient::builder()
27//! .tenant_id("your-tenant-id")
28//! .client_id("your-client-id")
29//! .client_secret("your-client-secret")
30//! .build()?;
31//!
32//! let request = SendMailRequest::new(Message {
33//! subject: "Hello from Graph".to_string(),
34//! body: wangamail_rs::MessageBody {
35//! content_type: BodyType::Text,
36//! content: "This email was sent via Microsoft Graph.".to_string(),
37//! },
38//! to_recipients: vec![
39//! Recipient::new("recipient@example.com"),
40//! ],
41//! ..Default::default()
42//! });
43//!
44//! client.send_mail("user@yourtenant.onmicrosoft.com", request).await?;
45//! # Ok(())
46//! # }
47//! ```
48//!
49//! ## Modules
50//!
51//! - **[`mcp`]** (optional, feature `mcp`): MCP server and **send_email** tool for AI tool use.
52
53#![warn(missing_docs)]
54
55mod auth;
56mod client;
57mod error;
58mod graph;
59
60#[cfg(feature = "mcp")]
61pub mod mcp;
62
63pub use client::{GraphMailClient, GraphMailClientBuilder};
64pub use error::{Error, Result};
65pub use graph::{
66 BodyType, EmailAddress, FileAttachment, Message, MessageBody, Recipient, SendMailRequest,
67};