Skip to content

Commit cf21ac7

Browse files
authored
Merge pull request #500 from OpenSignLabs/fix_Smtp
2 parents c929b6b + 5f11e92 commit cf21ac7

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

apps/OpenSignServer/index.js

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,26 +54,39 @@ if (process.env.USE_LOCAL !== 'TRUE') {
5454
let transporterMail;
5555
let mailgunClient;
5656
let mailgunDomain;
57-
57+
let isMailAdapter = false;
5858
if (process.env.SMTP_ENABLE) {
59-
transporterMail = createTransport({
60-
host: process.env.SMTP_HOST,
61-
port: process.env.SMTP_PORT || 465,
62-
secure: process.env.SMTP_SECURE || true,
63-
auth: {
64-
user: process.env.SMTP_USER_EMAIL,
65-
pass: process.env.SMTP_PASS,
66-
},
67-
});
59+
try {
60+
transporterMail = createTransport({
61+
host: process.env.SMTP_HOST,
62+
port: process.env.SMTP_PORT || 465,
63+
secure: process.env.SMTP_SECURE || true,
64+
auth: {
65+
user: process.env.SMTP_USER_EMAIL,
66+
pass: process.env.SMTP_PASS,
67+
},
68+
});
69+
await transporterMail.verify();
70+
isMailAdapter = true;
71+
} catch (err) {
72+
console.dir('Please provide valid SMTP credentials');
73+
isMailAdapter = false;
74+
}
6875
} else if (process.env.MAILGUN_API_KEY) {
69-
const mailgun = new Mailgun(formData);
70-
mailgunClient = mailgun.client({
71-
username: 'api',
72-
key: process.env.MAILGUN_API_KEY,
73-
});
74-
75-
mailgunDomain = process.env.MAILGUN_DOMAIN;
76+
try {
77+
const mailgun = new Mailgun(formData);
78+
mailgunClient = mailgun.client({
79+
username: 'api',
80+
key: process.env.MAILGUN_API_KEY,
81+
});
82+
mailgunDomain = process.env.MAILGUN_DOMAIN;
83+
isMailAdapter = true;
84+
} catch (error) {
85+
isMailAdapter = false;
86+
console.dir('Please provide valid Mailgun credentials');
87+
}
7688
}
89+
7790
export const config = {
7891
databaseURI:
7992
process.env.DATABASE_URI || process.env.MONGODB_URI || 'mongodb://localhost:27017/dev',
@@ -85,14 +98,14 @@ export const config = {
8598
masterKey: process.env.MASTER_KEY, //Add your master key here. Keep it secret!
8699
masterKeyIps: ['0.0.0.0/0', '::/0'], // '::1'
87100
serverURL: process.env.SERVER_URL || 'http://localhost:8080/app', // Don't forget to change to https if needed
88-
verifyUserEmails: process.env.SMTP_ENABLE || process.env.MAILGUN_API_KEY ? true : false,
101+
verifyUserEmails: isMailAdapter === true ? true : false,
89102
publicServerURL: process.env.SERVER_URL || 'http://localhost:8080/app',
90103
// Your apps name. This will appear in the subject and body of the emails that are sent.
91104
appName: 'Open Sign',
92105
allowClientClassCreation: false,
93106
allowExpiredAuthDataToken: false,
94107
encodeParseObjectInCloudFunction: true,
95-
...(process.env.SMTP_ENABLE || process.env.MAILGUN_API_KEY
108+
...(isMailAdapter === true
96109
? {
97110
emailAdapter: {
98111
module: 'parse-server-api-mail-adapter',

0 commit comments

Comments
 (0)