This Node.js application allows users to send emails with attachments. If the attachment is blocked due to security reasons, the file is uploaded to Google Drive and a link to the file is sent instead.
git clone https://github.com/Kushal2004/email-app.git
cd email-attachment-service/backend
npm install
- Set up environment variables: Create a .env file in the root of the backend directory and add the following:
EMAIL_USER=your-email@gmail.com
EMAIL_PASS=your-email-password
PORT=5000
- Add Google Drive credentials: Create a credentials.json file in the root of the backend directory and add the following:
{
"web": {
"client_id": "",
"project_id": "",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://oauth2.googleapis.com/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_secret": "",
"redirect_uris": [
"http://localhost:3000/oauth2callback/"
]
}
- Start the application
node app.js
- docker-compose.yml
The
docker-compose.yml
sets up the Docker services:
version: '3'
services:
app:
build: .
ports:
- "5000:5000"
environment:
- EMAIL_USER=your-email@gmail.com
- EMAIL_PASS=your-email-password
- PORT=5000
volumes:
- .:/usr/src/app
- Build and run the Docker container:
docker-compose up --build
- The application will be accessible at http://localhost:5000.
This API endpoint allows you to send an email with an attachment. If the attachment is blocked, it uploads the file to Google Drive and sends a link to the recipient.
- URL:
/api/email/send
- Method:
POST
- Description: Sends an email with an attachment. If the attachment is blocked, it uploads the file to Google Drive and sends a link.
recipientEmail
(string): The recipient's email address.subject
(string): The subject of the email.text
(string): The body of the email.attachment
(file): The attachment file.
curl -X POST http://localhost:5000/api/email/send \
-F "recipientEmail=example@example.com" \
-F "subject=Test Email" \
-F "text=This is a test email" \
-F "attachment=@path/to/your/file.zip"