Storing new mail from my mailbox into database - node.js

I want to store my new mails into postgresql database.
this is my main code, i was expecting it to show the new mail in console, but it won't
import {
MailListener,
IMailObject,
IMailAttachment
} from "mail-listener-typescript";
const options = {
username: "xxx#gmail.com", // mail
password: "xxx", // pass
host: "imap.gmail.com", // host
port: 993, // imap port
tls: true, // tls
connTimeout: 10000, // Default by node-imap
authTimeout: 5000, // Default by node-imap,
debug: console.log(), // Or your custom function with only one incoming argument. Default: null
tlsOptions: { rejectUnauthorized: false },
mailbox: "INBOX", // mailbox to monitor
searchFilter: ["NEW"], // the search filter being used after an IDLE notification has been retrieved
},
};
const MailListenerTS = new MailListener(options);
MailListenerTS.start();
MailListenerTS.on("mail", async function (mail: IMailObject, seqno: any, attributes: any) {
if (mail.attachments.length > 0) {
var mailAttachments: IMailAttachment[] = []
for (let attachment of mail.attachments) {
mailAttachments.push(attachment)
}
let mailData ={
name: mail.from.value[0].name,
sender: mail.from.value[0].address,
date: new Date(mail.date),
files: mailAttachments
}
console.log(mailData)
}
});
and my tables are:
context: id, subject, message
user: id, email

Related

Parse server rest password receiving email problem

I'm trying to implement the rest Password in my application so to do that I have added an email adapter to my server, like:
var parseServer = new ParseServer({
...
verifyUserEmails: false,
emailVerifyTokenValidityDuration: 24 * 60 * 60,
preventLoginWithUnverifiedEmail: false,
emailAdapter: !hasSMTPInfo ? undefined : {
module: 'parse-smtp-template',
options: {
port: env.EMAIL_PORT,
host: env.EMAIL_HOST,
user: env.EMAIL_USER,
password: env.EMAIL_PASSWORD,
fromAddress: env.EMAIL_FROMADDRESS,
template: false,
templatePath: env.EMAIL_TEMPLATEPATH
}
},
Rq: I have used the documentation of parse server api email from [documentation][1]
then I have implement the code of flutter part like:
final user = User(null, null, email);
await user.requestPasswordReset().then((value) async {
print(value.statusCode);
AlertUtils.showSuccessDialog('Veuillez vérifier votre boîte de réception')
.then((_) => Get.toNamed('/login'));
}).catchError((err) {
onDone.call();
AlertUtils.showErrorDialog(err.message.toString());
});
my problem is the status of response is 200 so every thing are right but I can't get any emails of restarting pw.
[1]: https://www.npmjs.com/package/parse-smtp-template

kafkajs - Wrong password for SASL authentication did not raise an error

This is my producer using kafkajs. When I provide incorrect user name in options.username, I see the message Connected. How do I handle connection errors with kafkajs?
const { Kafka, logLevel } = require('kafkajs')
async function kafkaProducer(options) {
const kafka = new Kafka({
brokers: [options.bootstrapServer],
clientId: options.clientId,
ssl: {
rejectUnauthorized: false,
ca: [fs.readFileSync(options.caCertPath, 'utf-8')]
},
sasl: {
mechanism: options.saslMechanism, // PLAIN
username: options.username,
password: options.password
},
requestTimeout: 2000,
retry: {
retries: 1
},
logLevel: logLevel.ERROR
})
//
const producer = kafka.producer()
try {
await producer.connect()
console.log('Connected')
} catch(e) {
throw new Error(e)
}
}
KafkaJS will throw an error on connect if authentication fails. See this test for example.
It is very likely that you haven't set up authentication on the broker side correctly. See the documentation for information on how to configure SASL on the broker.

prevent ffmpeg from opening console window

I have a node/express server which is used to give streams from IP camera to a website. Everything is working well. I run that webserver with PM2 on a windows server.
The problem : for each stream I have a windows console opening with just nothing logged in. The console reopen when I try to close it.
Is there a way to prevent those console to open ?
Here is the related node.js code :
const { NodeMediaServer } = require('node-media-server');
private _initiate_streams(): void{
DatabaseProvider.instance.camerasDao.getCamerasList().pipe(
take(1)
).subscribe(
(databaseReadOperationResult: DatabaseReadOperationResult<ICamera[]>) => {
if (databaseReadOperationResult.successful === true){
const cameras = databaseReadOperationResult.result;
const tasks = [];
cameras.forEach( camera => {
tasks.push(
{
app : config.get('media_server.app_name'),
mode: 'static',
edge: camera.rtsp_url,
name: camera.stream_name,
rtsp_transport: 'tcp'
}
)
});
const configMediaServer = {
logType: 3, // 3 - Log everything (debug)
rtmp: {
port: 1935,
chunk_size: 60000,
gop_cache: true,
ping: 60,
ping_timeout: 30
},
http: {
port: config.get('media_server.port'),
allow_origin: '*'
},
auth: {
play: true,
api: true,
publish: true,
secret: config.get('salt'),
api_user: 'user',
api_pass: 'password',
},
relay: {
ffmpeg: 'C:\\FFmpeg\\bin\\ffmpeg.exe',
tasks: tasks
}
};
var nms = new NodeMediaServer(configMediaServer)
nms.run();
} else {
// catch exception
}
}
);
}

trying to read mail with mail-listener4 Nodejs

I am using the sample code provided with the library in npm
npm link
var MailListener = require("mail-listener4");
var mailListener = new MailListener({
username: "******#gmail.com",
password: "***********",
host: "imap.gmail.com",
port: 993, // imap port
tls: true,
connTimeout: 10000,
authTimeout: 5000,
debug: console.log,
tlsOptions: { rejectUnauthorized: false },
mailbox: "INBOX", // mailbox to monitor
searchFilter: ["ALL"],
markSeen: true,
fetchUnreadOnStart: false,
mailParserOptions: {streamAttachments: true},
attachments: true,
attachmentOptions: { directory: "attachments/" }
});
mailListener.start(); // start listening
mailListener.on("error", function(err){
console.log(err);
});
this is the function that's called when a mail is recived :
but i don't know how it works
mailListener.on("mail", function(mail, seqno, attributes){
console.log("emailParsed");
// I know that i should get the mail body here
// but i don't know how
});
mailListener.on("attachment", function(attachment){
console.log(attachment.path);
});
i want to get the body of the mail as a string or xml
that's what i get on the console when i recive a mail
secreenshoot after reciving a mail

how to setup emailjs to send email

I am trying to use mailjs to send out email, and here is what I got:
var server = email.server.connect({
user: "something#mydomain.com",
password: "pw",
host: "smtp.office365.com",
port: "587",
tls: true
});
server.send({
text: "test!!",
from: "someemail#mydomain.com",
to: "recipient#somedomain.com",
subject: "hello"
}, function(err, message){console.log(err || message);});
The above code eventually throw me an error:
{ [Error: authorization.failed]
code: 3,
previous: { [Error: timedout while connecting to smtp server] code: 4, smtp: undefined },
smtp: undefined }
So basically my corporate email service is on office365, configured to use mydomain.com. I don't really know what does the user and password mean for the server, so I just used the sender's email and password. Is it anything wrong with my code? Maybe this is the problem?? Or otherwise what would it be?
First check and confirm host.Here is no need to use port: "587", tls: true.
You can use, this is wrking code
var server = email.server.connect({
user: 'abc#india.com',
password: 'vvq3tng$',
host: 'your host',
ssl: true,
});
server.send({
from: '<abc#india.com>', // sender address
to: '<xyz#india.com>',// list of receivers
cc: '',
subject: 'your subject', // Subject line
text: 'contant', // html body
}, function (err, message) {
if(err) {
console.log(err)
} else {
console.log("email sent")
}
});

Resources