Skip to main content

Crate wangamail_rs

Crate wangamail_rs 

Source
Expand description

§wangamail-rs

Send email on behalf of a Microsoft tenant using Microsoft Graph API and app registration credentials (OAuth2 client credentials flow). Part of the WangaMail family (wangamail-rs, wangamail-js, wangamail-py, wangamail-net).


Developed with love by 1nga Solutions · Logo: https://www.1nga.com/logo.svg

§Features

§Setup

  1. Register an application in Azure Portal → Microsoft Entra ID → App registrations.
  2. Create a client secret for the app.
  3. Under API permissions, add application permission Mail.Send for Microsoft Graph and grant admin consent.
  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).

§Example

use wangamail_rs::{GraphMailClient, Message, BodyType, Recipient, SendMailRequest};

let client = GraphMailClient::builder()
    .tenant_id("your-tenant-id")
    .client_id("your-client-id")
    .client_secret("your-client-secret")
    .build()?;

let request = SendMailRequest::new(Message {
    subject: "Hello from Graph".to_string(),
    body: wangamail_rs::MessageBody {
        content_type: BodyType::Text,
        content: "This email was sent via Microsoft Graph.".to_string(),
    },
    to_recipients: vec![
        Recipient::new("recipient@example.com"),
    ],
    ..Default::default()
});

client.send_mail("user@yourtenant.onmicrosoft.com", request).await?;

§Modules

  • [mcp] (optional, feature mcp): MCP server and send_email tool for AI tool use.

Structs§

EmailAddress
Email address (address + optional display name).
FileAttachment
File attachment (Graph fileAttachment; content as base64).
GraphMailClient
Client for sending email via Microsoft Graph (app-only, client credentials).
GraphMailClientBuilder
Builder for GraphMailClient.
Message
Message payload for sendMail.
MessageBody
Message body (content type + raw content).
Recipient
A single recipient (to, cc, or bcc).
SendMailRequest
Request body for POST /users/{id}/sendMail.

Enums§

BodyType
Body content type for the message.
Error
Errors that can occur when using the Graph mail client or MCP server.

Type Aliases§

Result
Result type alias using this crate’s [Error].