{"id":17774501,"url":"https://github.com/nekomeowww/exchange-smtp-client","last_synced_at":"2025-06-19T14:39:54.264Z","repository":{"id":90778059,"uuid":"411896158","full_name":"nekomeowww/exchange-smtp-client","owner":"nekomeowww","description":"Microsoft Exchange SMTP client example based on OAuth of Microsoft Graph in golang","archived":false,"fork":false,"pushed_at":"2021-11-19T10:25:18.000Z","size":5,"stargazers_count":4,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-01T15:41:46.045Z","etag":null,"topics":["golang","microsoft-azure-administrator","microsoft-graph-api","microsoft-oauth","smtp-client"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/nekomeowww.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-09-30T02:26:45.000Z","updated_at":"2025-03-31T22:07:38.000Z","dependencies_parsed_at":null,"dependency_job_id":"41fbd9d4-4d72-42bf-a297-68c2365d072d","html_url":"https://github.com/nekomeowww/exchange-smtp-client","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nekomeowww/exchange-smtp-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nekomeowww%2Fexchange-smtp-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nekomeowww%2Fexchange-smtp-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nekomeowww%2Fexchange-smtp-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nekomeowww%2Fexchange-smtp-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nekomeowww","download_url":"https://codeload.github.com/nekomeowww/exchange-smtp-client/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nekomeowww%2Fexchange-smtp-client/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260769864,"owners_count":23060192,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["golang","microsoft-azure-administrator","microsoft-graph-api","microsoft-oauth","smtp-client"],"created_at":"2024-10-26T21:51:05.238Z","updated_at":"2025-06-19T14:39:49.241Z","avatar_url":"https://github.com/nekomeowww.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Microsoft Exchange SMTP Example based on OAuth of Microsoft Graph\n\n## Implementation of XOAuth2 Authentication\n\n### Implementation\n\n```golang\n// SMTPAuth SMTPAuth\ntype SMTPAuth struct {\n\taccessToken string\n}\n\n// Auth auth\nfunc Auth(token string) smtp.Auth {\n\treturn \u0026SMTPAuth{token}\n}\n\n// Start start\nfunc (a *SMTPAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {\n\treturn \"xoauth2\", []byte(\"\"), nil\n}\n\n// Next next\nfunc (a *SMTPAuth) Next(fromServer []byte, more bool) ([]byte, error) {\n\tif more {\n\t\treturn []byte(a.accessToken), nil\n\t}\n\treturn nil, nil\n}\n```\n\n### Explaination\n\nStart a connection by running command:\n```shell\n$ openssl s_client -starttls smtp -ign_eof -crlf -connect smtp.office365.com:587\n```\n\n#### 1. Connection established, send `HELO` or `EHLO` command to server\n\n##### openssl connection example\n\n```\n[... SSL handshake...]\n\n250 SMTPUTF8\nHELO \u003cyour email host\u003e # Send HELO command to server\n250 BY3PR04CA0028.outlook.office365.com Hello [134.195.101.47]\n```\n\n##### client implementation explaination\n\nThe connection establishment has been implemented by net/smtp itself, we only need to implement the auth part by ourselves.\n\n#### 2. Send `AUTH XOAUTH2` command to SMTP server\n\n##### openssl connection example\n\n```\nAUTH XOAUTH2\n334 # server sends code `334` with message `(empty)` to client\n```\n\n##### client implementation explaination\n\n```golang\nfunc (a *SMTPAuth) Start(server *smtp.ServerInfo) (string, []byte, error) {\n\treturn \"xoauth2\", []byte(\"\"), nil // \"xoauth2\" is equivalent to \"XOAUTH2\"\n}\n```\n\n#### 3. Send base64 encoded access token to SMTP server\n\n##### openssl connection example\n\nCode 334 represents: Server challenge - the text part contains the Base64-encoded challenge ([SMTP return code reference](https://en.wikipedia.org/wiki/List_of_SMTP_server_return_codes))\n\n```\n334\n\u003cbase64 token\u003e\n235 2.7.0 Authentication successful\n```\n\n##### client implementation explaination\n\n```golang\n// at this point, SMTP server tells us that we need to take a challenge (provide our access token)\n// fromServer represents the message follow along with \"334\"\n// more tells us that one more step is required in order to complete the authentication (or flow)\nfunc (a *SMTPAuth) Next(fromServer []byte, more bool) ([]byte, error) {\n\tif more {\n        // sends the access token to the server\n\t\treturn []byte(a.accessToken), nil\n\t}\n\treturn nil, nil\n}\n```\n\n### Brief Summary\n\nEntire authentication flow:\n```\nHELO \u003cyour email host\u003e\n250 BY3PR04CA0028.outlook.office365.com Hello [134.195.101.47] \nAUTH XOAUTH2\n334\n\u003cbase64 token\u003e\n235 2.7.0 Authentication successful\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnekomeowww%2Fexchange-smtp-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnekomeowww%2Fexchange-smtp-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnekomeowww%2Fexchange-smtp-client/lists"}