Exchange Online mailbox operations via Microsoft Graph API: send emails, manage calendar events, export inbox.
Legacy name:
msgraphtool. The legacy binary was removed in v3.1. Usegomailtest msgraph <action> --flag(see the migration table in README.md).
# Set authentication via environment variables
$env:MSGRAPHTENANTID = "your-tenant-id"
$env:MSGRAPHCLIENTID = "your-client-id"
$env:MSGRAPHSECRET = "your-secret"
$env:MSGRAPHMAILBOX = "user@example.com"
# Get calendar events
gomailtest msgraph getevents
# Send test email
gomailtest msgraph sendmail --to "recipient@example.com"
# Get inbox messages
gomailtest msgraph getinbox --count 10gomailtest msgraph getevents
gomailtest msgraph getevents --count 10
gomailtest msgraph getevents --count 5 --verbose# Send to self (default)
gomailtest msgraph sendmail
# Send to specific recipient
gomailtest msgraph sendmail --to "recipient@example.com"
# Custom subject and body
gomailtest msgraph sendmail \
--to "recipient@example.com" \
--subject "Test Email" \
--body "This is a test message"
# Multiple recipients with CC and BCC
gomailtest msgraph sendmail \
--to "user1@example.com,user2@example.com" \
--cc "cc@example.com" \
--bcc "bcc@example.com" \
--subject "Team Update"
# HTML email
gomailtest msgraph sendmail \
--to "recipient@example.com" \
--subject "HTML Email" \
--bodyHTML "<h1>Hello</h1><p>This is an <strong>HTML</strong> email.</p>"
# With attachments
gomailtest msgraph sendmail \
--to "recipient@example.com" \
--subject "Report Attached" \
--attachments "C:\Reports\report.pdf,C:\Data\spreadsheet.xlsx"gomailtest msgraph sendinvite --subject "Team Meeting"
gomailtest msgraph sendinvite \
--subject "Project Review" \
--start "2026-01-15T14:00:00Z" \
--end "2026-01-15T15:00:00Z"gomailtest msgraph getinbox
gomailtest msgraph getinbox --count 20gomailtest msgraph getschedule --to "colleague@example.com"gomailtest msgraph exportinbox --count 50Output goes to %TEMP%\export\{date}\message_{n}_{timestamp}.json.
gomailtest msgraph searchandexport --messageid "<message-id@example.com>"| Flag | Description | Environment Variable | Default |
|---|---|---|---|
--tenantid |
Azure AD Tenant ID (GUID) | MSGRAPHTENANTID |
— |
--clientid |
Application (Client) ID (GUID) | MSGRAPHCLIENTID |
— |
--mailbox |
Target user email address | MSGRAPHMAILBOX |
— |
--secret |
Client Secret | MSGRAPHSECRET |
— |
--pfx |
Path to .pfx certificate file | MSGRAPHPFX |
— |
--pfxpass |
Password for .pfx certificate | MSGRAPHPFXPASS |
— |
--thumbprint |
Certificate thumbprint (Windows only) | MSGRAPHTHUMBPRINT |
— |
--bearertoken |
Pre-obtained Bearer token | MSGRAPHBEARERTOKEN |
— |
--proxy |
HTTP/HTTPS proxy URL | MSGRAPHPROXY |
— |
--maxretries |
Maximum retry attempts | MSGRAPHMAXRETRIES |
3 |
--retrydelay |
Retry delay (milliseconds) | MSGRAPHRETRYDELAY |
2000 |
--count |
Number of items to retrieve | MSGRAPHCOUNT |
3 |
--verbose |
Enable verbose output | — | false |
--loglevel |
Log level: DEBUG, INFO, WARN, ERROR | MSGRAPHLOGLEVEL |
INFO |
--logformat |
Log file format: csv, json | MSGRAPHLOGFORMAT |
csv |
| Flag | Description | Environment Variable |
|---|---|---|
--to |
Comma-separated TO recipients | MSGRAPHTO |
--cc |
Comma-separated CC recipients | MSGRAPHCC |
--bcc |
Comma-separated BCC recipients | MSGRAPHBCC |
--subject |
Email subject | MSGRAPHSUBJECT |
--body |
Email body text | MSGRAPHBODY |
--bodyHTML |
Email body HTML | MSGRAPHBODYHTML |
--body-template |
Path to HTML template file | MSGRAPHBODYTEMPLATE |
--attachments |
Comma-separated file paths | MSGRAPHATTACHMENTS |
--start |
Start time (RFC3339) | MSGRAPHSTART |
--end |
End time (RFC3339) | MSGRAPHEND |
--messageid |
Internet Message ID | MSGRAPHMESSAGEID |
Provide exactly one method. Mutually exclusive:
gomailtest msgraph getevents \
--tenantid "..." --clientid "..." \
--secret "your-client-secret" \
--mailbox "user@example.com"gomailtest msgraph getevents \
--tenantid "..." --clientid "..." \
--pfx "C:\Certs\app-cert.pfx" --pfxpass "certificate-password" \
--mailbox "user@example.com"gomailtest msgraph getevents \
--tenantid "..." --clientid "..." \
--thumbprint "CD817B3329802E692CF30D8DDF896FE811B048AB" \
--mailbox "user@example.com"gomailtest msgraph getevents \
--tenantid "..." --clientid "..." \
--bearertoken "eyJ0eXAi..." \
--mailbox "user@example.com"$env:MSGRAPHTENANTID = "tenant-id"
$env:MSGRAPHCLIENTID = "client-id"
$env:MSGRAPHSECRET = "your-secret"
$env:MSGRAPHMAILBOX = "user@example.com"
gomailtest msgraph sendmail --to "recipient@example.com"Operations are logged to %TEMP%\_msgraphtool_{action}_{date}.csv.
# Custom retry settings
gomailtest msgraph getevents --maxretries 5 --retrydelay 3000
# Disable retries
gomailtest msgraph sendmail --maxretries 0Retry uses exponential backoff: 2s → 4s → 8s → 16s → 30s (capped). Retries on HTTP 429, 503, 504, network timeouts. Never retries authentication failures or 4xx errors.
| Action | Permission |
|---|---|
| sendmail | Mail.Send |
| getevents, sendinvite | Calendars.ReadWrite |
| getinbox, exportinbox, searchandexport | Mail.Read |
| getschedule | Calendars.Read |
-
BUILD.md — Build instructions
-
EXAMPLES.md — Extended usage examples
-
TROUBLESHOOTING.md — Common issues
-
SECURITY.md — Security policy
..ooOO END OOoo..