Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Insecure Mail Transport #55

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions utils/data/configs.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,16 @@ export default class ProjectConfigs {
configs.custom_template.enabled = customTemplateEnabled === 'on' ?? false;

// mail configurations
configs.mail = [...email.map(({batch_size, delay_per_batch, auth_user, auth_pass, ...rest}) => {
configs.mail = [...email.map(({batch_size, delay_per_batch, auth_user, auth_pass, secure, ...rest}) => {
return {
...rest,
batch_size: parseInt(batch_size),
delay_per_batch: parseInt(delay_per_batch),
auth: {
user: auth_user,
pass: auth_pass
}
},
secure: secure === 'on' ? true : false
};
})];

Expand Down Expand Up @@ -311,4 +312,4 @@ export default class ProjectConfigs {
this.ghoslerVersion = JSON.parse(fileContent).version;
}).catch((_) => this.ghoslerVersion = '');
}
}
}
27 changes: 20 additions & 7 deletions utils/mail/mailer.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,25 @@ export default class NewsletterMailer {
* @returns {Promise<*>} - The configured transporter.
*/
async #transporter(mailConfig) {
return nodemailer.createTransport({
secure: true,
host: mailConfig.host,
port: mailConfig.port,
auth: {user: mailConfig.auth.user, pass: mailConfig.auth.pass}
});
// Destructure from mailConfig, defaulting secure to true if not specified
const { secure = true, host, port, auth } = mailConfig;

// Initialize transport options
const transportOptions = {
secure,
host,
port
};

// Conditionally add auth if both user and pass are provided
if (auth && auth.user && auth.pass) {
transportOptions.auth = {
user: auth.user,
pass: auth.pass
};
}

return nodemailer.createTransport(transportOptions);
}

/**
Expand Down Expand Up @@ -256,4 +269,4 @@ export default class NewsletterMailer {

return emailsSent;
}
}
}
19 changes: 15 additions & 4 deletions views/dashboard/settings.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<div id="mailConfigInner${mailConfigIndex}" class="mt-4" style="display: none;">
<div class="form-group mb-4">
<label for="email[${mailConfigIndex}][reply_to]" class="block text-gray-300 mb-1">Reply To</label>
<input type="text" placeholder="'Author' <[email protected]> [Optional]" id="email[${mailConfigIndex}][reply_to]" name="email[${mailConfigIndex}][reply_to]" required class="shadow appearance-none border border-gray-600 rounded w-full py-2 px-3 bg-gray-700 text-white" />
<input type="text" placeholder="'Author' <[email protected]> [Optional]" id="email[${mailConfigIndex}][reply_to]" name="email[${mailConfigIndex}][reply_to]" class="shadow appearance-none border border-gray-600 rounded w-full py-2 px-3 bg-gray-700 text-white" />
</div>

<div class="form-group mb-4">
Expand All @@ -64,14 +64,25 @@
<input type="number" inputmode="numeric" placeholder="587" id="email[${mailConfigIndex}][port]" name="email[${mailConfigIndex}][port]" required class="shadow appearance-none border border-gray-600 rounded w-full py-2 px-3 bg-gray-700 text-white" />
</div>

<div class="form-group mb-4">
<div class="flex items-center">
<input type="checkbox" class="form-checkbox h-4 w-4 text-blue-600 rounded border-gray-600 mr-2"
id="email[${mailConfigIndex}][secure]" name="email[${mailConfigIndex}][secure]"
<% if (Boolean(configs.mail[configs.mail.length - 1].secure)) { %> checked
<% } %>
>
<label for="email[${mailConfigIndex}][secure]" class="text-gray-300">Secure</label>
</div>
</div>

<div class="form-group mb-4">
<label for="email[${mailConfigIndex}][auth_user]" class="block text-gray-300 mb-1">Auth User</label>
<input type="text" placeholder="Email Username" id="email[${mailConfigIndex}][auth_user]" name="email[${mailConfigIndex}][auth_user]" required class="shadow appearance-none border border-gray-600 rounded w-full py-2 px-3 bg-gray-700 text-white" />
<input type="text" placeholder="Email Username" id="email[${mailConfigIndex}][auth_user]" name="email[${mailConfigIndex}][auth_user]" class="shadow appearance-none border border-gray-600 rounded w-full py-2 px-3 bg-gray-700 text-white" />
</div>

<div class="form-group mb-4">
<label id="email[${mailConfigIndex}][auth_pass]" class="block text-gray-300 mb-1">Auth Password</label>
<input type="password" placeholder="Email Password" id="email[${mailConfigIndex}][auth_pass]" name="email[${mailConfigIndex}][auth_pass]" required class="shadow appearance-none border border-gray-600 rounded w-full py-2 px-3 bg-gray-700 text-white" />
<input type="password" placeholder="Email Password" id="email[${mailConfigIndex}][auth_pass]" name="email[${mailConfigIndex}][auth_pass]" class="shadow appearance-none border border-gray-600 rounded w-full py-2 px-3 bg-gray-700 text-white" />
</div>

<div class="form-group mb-4">
Expand Down Expand Up @@ -165,4 +176,4 @@
<%- include('../partials/common/footer.ejs') %>

</body>
</html>
</html>
19 changes: 15 additions & 4 deletions views/partials/settings/mail.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
To</label>
<input type="text" placeholder="'Author' <[email protected]> [Optional]"
id="email[<%= index; %>][reply_to]"
name="email[<%= index; %>][reply_to]" value="<%= config.reply_to; %>" required
name="email[<%= index; %>][reply_to]" value="<%= config.reply_to; %>"
class="shadow appearance-none border border-gray-600 rounded w-full py-2 px-3 bg-gray-700 text-white">
</div>

Expand Down Expand Up @@ -56,12 +56,23 @@
class="shadow appearance-none border border-gray-600 rounded w-full py-2 px-3 bg-gray-700 text-white">
</div>

<div class="form-group mb-4">
<div class="flex items-center">
<input type="checkbox" class="form-checkbox h-4 w-4 text-blue-600 rounded border-gray-600 mr-2"
id="email[<%= index; %>][secure]" name="email[<%= index; %>][secure]"
<% if (Boolean(configs.mail[index].secure)) { %> checked
<% } %>
>
<label for="email[<%= index; %>][secure]" class="text-gray-300">Secure</label>
</div>
</div>

<div class="form-group mb-4">
<label for="email[<%= index; %>][auth_user]" class="block text-gray-300 mb-1">Auth
User</label>
<input type="text" placeholder="Email Username"
id="email[<%= index; %>][auth_user]"
name="email[<%= index; %>][auth_user]" value="<%= config.auth.user; %>" required
name="email[<%= index; %>][auth_user]" value="<%= config.auth.user; %>"
class="shadow appearance-none border border-gray-600 rounded w-full py-2 px-3 bg-gray-700 text-white">
</div>

Expand All @@ -70,7 +81,7 @@
Password</label>
<input type="password" placeholder="Email Password"
id="email[<%= index; %>][auth_pass]"
name="email[<%= index; %>][auth_pass]" value="<%= config.auth.pass; %>" required
name="email[<%= index; %>][auth_pass]" value="<%= config.auth.pass; %>"
class="shadow appearance-none border border-gray-600 rounded w-full py-2 px-3 bg-gray-700 text-white">
</div>

Expand Down Expand Up @@ -107,4 +118,4 @@
class="bg-gray-600 hover:bg-gray-700 text-white font-bold py-2 px-4 rounded mt-4">Add New
</button>
</div>
</div>
</div>