Closed steven4354 closed 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:
Here's an example using Python, schedule
library for cron, smtplib
for sending emails, and google-api-python-client
for Gmail API:
...
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:
npm install node-cron nodemailer googleapis
Create a credentials.json
file with your Gmail API credentials.
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 ()...
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