This project represents a system for the automatic classification of incoming emails using Google's Gemini model. It connects to an IMAP server, processes emails, classifies them, and moves them to appropriate folders based on their content.
If you find this project useful, you can support it through Revolut: https://revolut.me/chuk1.
For proper functioning of the project, the following dependencies need to be installed:
- go-imap — a library for working with IMAP servers.
- generative-ai-go — a library for working with Google Gemini.
- google-api-go-client — a client for Google APIs.
To install the dependencies, use Go Modules.
-
Initialize Go Modules if not already done:
go mod init email-classification
-
Install the required packages:
go get github.com/BrianLeishman/go-imap go get github.com/google/generative-ai-go/genai go get google.golang.org/api/option
-
Optional: You can create a
credentials.json
file in the root directory of the project, which will contain your login and password if you wish to save credentials for future use.File format:
{ "login": "your-email", "password": "your-password" }
-
If you don't want to use the
credentials.json
file, the program will prompt you to enter login and password every time you run it. -
Fill in the
apiKey
variable in the code with your Google Gemini API key. -
Modify the IMAP server settings if necessary.
-
Run the project with the following command:
go run main.go
-
The program will prompt you to enter your login and password, and then it will begin processing emails.
-
The program will classify emails and move them to appropriate folders.
Example program output:
Connecting to IMAP... Login successful. Starting email processing... Getting folders... Folder: INBOX Processing email: Hello, World! Classifying email... Subject: Hello, World! Senders: sender@example.com Email classified as: INBOX Email not moved to folder: INBOX