feat: Implement SMTP app connection

This commit is contained in:
Faruk AYDIN
2021-10-25 16:49:03 +02:00
committed by Ali BARIN
parent 9e3c61e3df
commit ce7130b271
6 changed files with 264 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
import nodemailer from 'nodemailer';
import App from '../../models/app';
export default class SMTP {
client: any
connectionData: any
appData: any
constructor(connectionData: any) {
this.client = nodemailer.createTransport({
host: connectionData.host,
port: connectionData.port,
secure: connectionData.useTls,
auth: {
user: connectionData.username,
pass: connectionData.password,
},
});
this.connectionData = connectionData;
this.appData = App.findOneByKey('smtp');
}
async verifyCredentials() {
await this.client.verify()
return {
screenName: this.connectionData.username
}
}
async isStillVerified() {
try {
await this.client.verify()
return true;
} catch(error) {
return false
}
}
}