-
Notifications
You must be signed in to change notification settings - Fork 19
/
funcsback.js
54 lines (46 loc) · 1.77 KB
/
funcsback.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const nodemailer = require("nodemailer");
const path = require("path");
class Funcs {
constructor() {}
sendmail(the_mail_address,mail_address, subject, message) {
// You should enter your mail informations the "transfer" object below.
// This settings are for gmail , please update them if you use another mail service.
// Also this informations for sender mail which is sending mails from contact page to your original mail address
// You can use your original mail address too , does not matter.
// But you should make security low for sender mail address , please take a look : https://stackoverflow.com/questions/45478293/username-and-password-not-accepted-when-using-nodemailer
var transfer = nodemailer.createTransport({
service: "gmail",
host: 'smtp.gmail.com',
port: 587,
secure: false,
requireTLS: true,
auth: {//for sender
user: "",
pass: ""
}
});
var mail_info = {
from: mail_address,
to: the_mail_address,
subject: subject + " - from:" + mail_address,
text: message,
};
transfer.sendMail(mail_info, function(error) {
if (error) throw error;
});
}
checkFileType(file, cb) {
// Allowed ext
const filetypes = /jpeg|jpg|png|svg|ico/;
// Check ext
const extname = filetypes.test(path.extname(file.originalname).toLowerCase());
// Check mime
const mimetype = filetypes.test(file.mimetype);
if (mimetype && extname) {
return cb(null, true);
} else {
cb('Error: Images Only!');
}
}
}
module.exports = Funcs;