smtp2zoho
works as a proxy, receiving SMTP messages, forwarding mails to Zoho Mail API.
It is usually used to hide sender's IP address when using SMTP.
In other words, it is a middleware between an app that sending mails via SMTP and Zoho Mail API, "updating" the app to support Zoho Mail API silently and non-invasively.
Undoubtedly, Zoho has been providing native SMTP access for all users.
However, It is a problem that sending mail via SMTP could expose the IP address of sender.
Receiver could check mail headers (it is easy as you want), which contains Received
header, indicating sender IP address.
When you are sending a mail by web app or HTTP API, IP of sender would not contained in headers. That is what it based on to avoid IP exposure.
Configure options are contained in "config.yml". Deploy your own Zoho access credential and specify fake SMTP server listen address.
First, create a "Self Client".
Get authorization code with this scope: "ZohoMail.accounts.READ,ZohoMail.messages.CREATE".
Now your have Client ID
, Client Secret
and Authorization Code
.
Request this API to get Access Token
and Refresh Token
. (doc: https://www.zoho.com/mail/help/api/using-oauth-2.html)
POST /oauth/v2/token
Host: accounts.zoho.com
Content-Type: application/x-www-form-urlencoded
form data:
client_id: <ClientID>
client_secret: <ClientSecret>
grant_type: authorization_code
code: <AuthorizationCode>
It will response with Access Token
and Refresh Token
.
Request this API to get account ID. (doc: https://www.zoho.com/mail/help/api/get-user-account-details.html)
GET /api/accounts
Host: mail.zoho.com
Authorization: Bearer <AccessToken>
It will response with user info, including Account ID
(field name is "accountId").
Fill the required credentials into "config.yml". The field "ZohoMailAddr" is the sender's mail address. Understand that passing sender address in SMTP context with "MAIL FROM" command is just used to make a standard SMTP process. It won't be contained in HTTP request.
Update the field "smtpListen".
Run it as other Go programs. No command arguments are required.
- DO NOT expose the SMTP server in public network. It is weak, non-standard SMTP session could make it panicked. And currently, there's no authentication option provided.
- If you want to specify sender display name, use
From
header in raw mail data. Here are some examples:
# normal
From: Specified Name <[email protected]>
# UTF-8 encoded
From: =?UTF-8?B?5Y+R6YCB6ICF?= <[email protected]>
# if you don't want to specify it, just leave it blank
From: <[email protected]>
Subject
header only allow formats below:
Subject: TestSubject
Subject: =?UTF-8?B?VGVzdEhlYWRlcg==?=
- Make issues or pull requests if you want to improve the project.