Skip to content

Commit

Permalink
use mail adapter instead of using a client directly
Browse files Browse the repository at this point in the history
  • Loading branch information
LizardEngineer committed Nov 5, 2024
1 parent ab13726 commit 90019d4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 22 deletions.
9 changes: 8 additions & 1 deletion ghost/core/config.development.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
{
"enableDeveloperExperiments": true
"enableDeveloperExperiments": true,
"adapters": {
"mail": {
"active": "mailgun",
"mailgun": {},
"postmark": {}
}
}
}
1 change: 1 addition & 0 deletions ghost/core/content/adapters/mail/mailgun.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@tryghost/mailgun-client');
1 change: 1 addition & 0 deletions ghost/core/content/adapters/mail/postmark.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('../../../../postmark-client');
2 changes: 1 addition & 1 deletion ghost/core/core/server/services/adapter-manager/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ adapterManager.registerAdapter('storage', require('ghost-storage-base'));
adapterManager.registerAdapter('scheduling', require('../../adapters/scheduling/scheduling-base'));
adapterManager.registerAdapter('sso', require('../../adapters/sso/SSOBase'));
adapterManager.registerAdapter('cache', require('@tryghost/adapter-base-cache'));
adapterManager.registerAdapter('mail', require('../../../../../mailgun-client/index'));
adapterManager.registerAdapter('mail', require('../../adapters/mail/MailAdapterBase'));

module.exports = {
/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const logging = require('@tryghost/logging');
const url = require('../../api/endpoints/utils/serializers/output/utils/url');
const MailgunClient = require('@tryghost/mailgun-client');
const PostmarkClient = require('@tryghost/postmark-client');
const adapterManager = require('../adapter-manager');
const configService = require('../../../shared/config');
const settingsCache = require('../../../shared/settings-cache');
const mailClient = adapterManager.getAdapter('mail', undefined, {config: configService, settings: settingsCache});

class EmailServiceWrapper {
getPostUrl(post) {
Expand All @@ -10,18 +12,8 @@ class EmailServiceWrapper {
return jsonModel.url;
}

getMailClient(settingsCache, configService) {
if (settingsCache.get('bulk_email_provider') === 'postmark') {
// Postmark client instance for email provider
return new PostmarkClient({
config: configService, settings: settingsCache
});
}

// Mailgun client instance for email provider
return new MailgunClient({
config: configService, settings: settingsCache
});
getMailClient() {
return mailClient;
}

init() {
Expand All @@ -31,8 +23,6 @@ class EmailServiceWrapper {

const {EmailService, EmailController, EmailRenderer, SendingService, BatchSendingService, EmailSegmenter, BulkEmailProvider} = require('@tryghost/email-service');
const {Post, Newsletter, Email, EmailBatch, EmailRecipient, Member} = require('../../models');
const configService = require('../../../shared/config');
const settingsCache = require('../../../shared/settings-cache');
const settingsHelpers = require('../settings-helpers');
const jobsService = require('../jobs');
const membersService = require('../members');
Expand Down Expand Up @@ -60,8 +50,6 @@ class EmailServiceWrapper {
sentry.captureException(error);
};

let mailClient = this.getMailClient(settingsCache, configService);

const bulkEmailProvider = new BulkEmailProvider({
mailClient,
errorHandler
Expand Down
2 changes: 1 addition & 1 deletion ghost/mailgun-client/lib/MailgunClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ module.exports = class MailgunClient extends MailAdapterBase {
* @param {Object} mailgunConfig
* @param {Object} mailgunOptions
*/
async getEventsFromMailgun(mailgunInstance, mailgunConfig, mailgunOptions) {
async getEvents(mailgunInstance, mailgunConfig, mailgunOptions) {
const startTime = Date.now();
try {
const page = await mailgunInstance.events.get(mailgunConfig.domain, mailgunOptions);
Expand Down
2 changes: 1 addition & 1 deletion ghost/postmark-client/lib/PostmarkClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module.exports = class PostmarkClient extends MailAdapterBase {
* @param {ServerClient} postmarkInstance
* @param {Date} startTime
*/
async getEventsFromPostmark(postmarkInstance, startTime) {
async getEvents(postmarkInstance, startTime) {
try {
const page = await postmarkInstance.getMessageOpens();
metrics.metric('postmark-get-events', {
Expand Down

0 comments on commit 90019d4

Please sign in to comment.