The GMail Application Program Interface (API) is written in Javascript. PHP is required. The programs talk ONLY to Google and your data is not shared with anyone.
Here is a video demonstration:
1. How does it works?
- Download the zip file. Extract contents to www directory of WAMP. (See Section 2). Rename the folder to SaveGMailAsEML.
- Go to SaveGMailAsEML folder and open backup.php file in Notepad. Find CLIENT_ID and replace your-google-client-id with your client id obtained in step 3. Save and close.
- Open Chrome and type in -> http://localhost/SaveGMailAsEML/backup.php
- Click on Login With GMail. Type in your username and password. If you are already logged in, you will directed to Request For Permission page. Click Allow. You will be directed to app homepage.
- After initialization, you will find your GMail labels under Labels.
- Choose a GMail label and click on Start Back UP.
- A folder will be created in SaveGMailAsEML folder with name of your GMail label. Sub-folders will be created within that folder for pages and emails without attachments.
- Status message appears on webpage when download is complete.
The downloaded emails are in .eml format. They can be viewed using Windows Live Mail or Windows Mail 10.
The time limit for receiving data from Google is 30 seconds (which is adjustable). If time exceeds 30 seconds, then the email is saved without attachment.
It is recommended to run the program while keeping the console window open. The code has been tested on Chrome Version 54.0.2840.71.The source-code can be easily modified.
In order to use this application, there are few prerequisites:
2. Localhost
You need to have localhost server. Many localhost servers are available. I have used WAMP. The website is http://www.wampserver.com/en/.
Here is a link to YouTube video on how to install:
Before you download WAMP, ensure you have downloaded the prerequisite software.
Troubleshooting some common errors
-
PHP Warning: Unknown: POST Content-Length of X bytes exceeds the limit of 8388608 bytes in Unknown on line 0
a. Open php.ini file. b. Find post_max_size. Change limit from 8M to 2000M. If problem still occurs, change limit further.
3. How to get Google Client ID?
- Login to your GMail account.
- Open link -> https://console.developers.google.com/flows/enableapi?apiid=gmail
- Select Create a Project and continue.
- Once GMail API is enabled, click on Go to credential's.
- Click on client ID. Click Configure consent screen.
- In product name, type SaveGMailAsEML and save.
- Select Web application.
- In Authorized JavaScript origins, type in http://localhost.
- Click Create.
- Copy your client ID.
4. Enable IMAP in GMail.
5. Known errors and solutions:
The access token is valid for 1 hour. If the program runs for more than 1 hour, an error will be shown in console window. When this happens refresh and run again. Use the Continue from page option and structure your query using label, dates, to, from, subject fields to start where you had left off.
Sometimes you may get resource exceeded or quota error. When this happens, refresh and use the guide above to structure your query to start where you had left off.
Sometimes you mat get Aw, Snap error. Refresh and start again.