EmailProvidersOutlook365

Outlook365

Send emails through Microsoft Graph (Outlook365) with @visulima/email

Outlook365 Provider

The Outlook365 provider sends emails through the Microsoft Graph sendMail endpoint.

Runtime Support: Universal (Node.js, Deno, Bun, Cloudflare Workers) — uses the Fetch API.

Authentication is delegated: you supply a static accessToken or an async getAccessToken (e.g. backed by @azure/msal-node). The provider never bundles an auth SDK, so it stays dependency-light and runtime-agnostic.

Setup

import { createMail } from "@visulima/email";
import { outlook365Provider } from "@visulima/email/providers/outlook365";

const mail = createMail(
    outlook365Provider({
        // Bring your own OAuth2 token with the `Mail.Send` scope.
        getAccessToken: async () => getGraphAccessToken(),
        userId: "sender@contoso.com", // or "me" (default) to use the token's own mailbox
    }),
);

Configuration

The Outlook365Config interface extends BaseConfig. One of accessToken / getAccessToken is required.

OptionTypeRequiredDefaultDescription
accessTokenstringCond.-Static OAuth2 token with the Mail.Send scope
getAccessToken() => MaybePromise<string>Cond.-Returns a fresh OAuth2 token (preferred for expiring tokens)
userIdstringNomeMailbox to send as (user id / UPN)
saveToSentItemsbooleanNotrueKeep a copy in the Sent Items folder
endpointstringNohttps://graph.microsoft.com/v1.0Custom Graph endpoint
debugbooleanNofalseEnable debug logging
loggerConsoleNo-Custom logger instance
retriesnumberNo3Number of retry attempts
timeoutnumberNo30000Request timeout in milliseconds

Basic Usage

const result = await mail.send({
    from: { email: "sender@contoso.com" },
    to: { email: "user@example.com" },
    subject: "Hello from Outlook365",
    html: "<h1>Welcome!</h1>",
});

Note: Microsoft Graph always sends as the authenticated user / userId, so the from address is effectively the mailbox the token is scoped to. Graph's sendMail returns 202 Accepted with an empty body, so a message id is synthesised in the result.

Provider-Specific Email Options

The Outlook365EmailOptions interface extends EmailOptions with:

OptionTypeDescription
importance"high" | "low" | "normal"Message importance

Supported Features

  • ✅ Attachments
  • ✅ Custom headers
  • ✅ HTML & text bodies
  • ✅ Reply-To
  • ❌ Batch sending
  • ❌ Tagging / templates / tracking (use Graph directly for those)
Support

Contribute to our work and keep us going

Community is the heart of open source. The success of our packages wouldn't be possible without the incredible contributions of users, testers, and developers who collaborate with us every day.Want to get involved? Here are some tips on how you can make a meaningful impact on our open source projects.

Ready to help us out?

Be sure to check out the package's contribution guidelines first. They'll walk you through the process on how to properly submit an issue or pull request to our repositories.

Submit a pull request

Found something to improve? Fork the repo, make your changes, and open a PR. We review every contribution and provide feedback to help you get merged.

Good first issues

Simple issues suited for people new to open source development, and often a good place to start working on a package.
View good first issues