listeven989 / email.dev

open sourced email outbound
https://emaildev.vercel.app
1 stars 2 forks source link

feature: spam detection #45

Closed steven4354 closed 1 year ago

steven4354 commented 1 year ago

a cron that runs every day through all the email accounts and checks if an email sent from that account to a gmail account ends up in spam or in inbox

if it ends up in spam, indicate it somehow in the UI

steven4354 commented 1 year ago

I am a helpful assistant! How can I help?


a cron that runs every day through all the email accounts and checks if an email sent from that account to a gmail account ends up in spam or in inbox

if it ends up in spam, indicate it somehow in the UI


To achieve this, you can follow these steps:

  1. Set up a cron job that runs every day.
  2. Use an email library to send an email from each account to a Gmail account.
  3. Use Gmail API to check if the email ends up in the spam folder or inbox.
  4. Update the UI based on the result.

Here's an example using Python, schedule library for cron, smtplib for sending emails, and google-api-python-client for Gmail API:

  1. Install required libraries:

...


instead of python use typescript


Sure! Here's an example using TypeScript, node-cron for cron jobs, nodemailer for sending emails, and googleapis for Gmail API:

  1. Install required libraries:
npm install node-cron nodemailer googleapis
  1. Create a credentials.json file with your Gmail API credentials.

  2. Create a checkEmail.ts file with the following code:

import * as cron from 'node-cron';
import * as nodemailer from 'nodemailer';
import { google } from 'googleapis';

const emailAccounts = [
  {
    email: 'your-email@example.com',
    password: 'your-password',
  },
  // Add more email accounts here
];

const testGmailAccount = 'your-test-gmail-account@gmail.com';

const checkEmail = async () => {
  for (const account of emailAccounts) {
    const transporter = nodemailer.createTransport({
      service: 'your-email-service', // e.g., 'gmail', 'yahoo', etc.
      auth: {
        user: account.email,
        pass: account.password,
      },
    });

    const mailOptions = {
      from: account.email,
      to: testGmailAccount,
      subject: 'Test email',
      text: 'This is a test email to check if it ends up in spam or inbox.',
    };

    await transporter.sendMail(mailOptions);

    const { client_email, private_key } = require('./credentials.json');
    const oAuth2Client = new google.auth.JWT(client_email, undefined, private_key, [
      'https://www.googleapis.com/auth/gmail.readonly',
    ]);

    await oAuth2Client.authorize();

    const gmail = google.gmail({ version: 'v1', auth: oAuth2Client });
    const query = `from:${account.email} subject:"${mailOptions.subject}"`;

    const checkInbox = async ()...