Add steps and functionality for using SES and SNS for email

This commit is contained in:
Thomas Rogers 2024-11-03 17:27:36 +01:00
parent b8226dbac0
commit af70b2504f
17 changed files with 67 additions and 9 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 452 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 543 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 312 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 120 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 260 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 160 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

View file

@ -1,9 +1,5 @@
import { RedisDataSource } from '@omnivore/utils'
import express, {
Express,
Request,
Response,
} from 'express'
import express, { Express, Request, Response } from 'express'
import { env } from './env'
import { getQueue } from './lib/queue'
@ -16,6 +12,13 @@ console.log('Starting worker...')
const app: Express = express()
app.use(express.text({ limit: '50mb' }))
// Force JSON for SNS
app.use((req, res, next) => {
req.headers['content-type'] = 'application/json'
next()
})
app.use(express.json({ limit: '50mb' }))
app.use(express.urlencoded({ limit: '50mb', extended: true }))
@ -63,23 +66,38 @@ app.get('/_ah/health', (_req: Request, res: Response) => {
app.post('/mail', addEmailEventToQueue)
app.post('/sns', async (req, res) => {
const snsMessage = req.body as SnsMessage
const bodyString = req.body as string
const snsMessage = JSON.parse(bodyString) as SnsMessage
console.log(`Received SNS Message`, snsMessage)
console.log(`Sns Topic ARN ${snsMessage['TopicArn']}`)
if (snsMessage.TopicArn != env.sns.snsArn) {
console.log(`Topic ARN: ${snsMessage.TopicArn} Doesnt Match ${env.sns.snsArn}, failing...`)
res.status(401).send()
return
}
if (snsMessage.Type == 'SubscriptionConfirmation') {
console.log('Subscribing to topic')
await axios.get(snsMessage.SubscribeURL)
res.status(200).send()
return
}
if (snsMessage.Type == 'Received') {
const mailContent = await simpleParser(snsMessage.content)
const mail = convertToMailObject(mailContent)
if (snsMessage.Type == 'Notification') {
const message = JSON.parse(snsMessage.Message) as {
notificationType: string
content: string
}
if (message.notificationType != 'Received') {
console.log('Not an email, failing...')
res.status(400).send()
}
const mailContent = await simpleParser(message.content)
const mail = convertToMailObject(mailContent)
console.log(mail)
await (
await queue
).add('save-newsletter', mail, {

View file

@ -3,4 +3,5 @@ export type SnsMessage = {
TopicArn: string
SubscribeURL: string
content: string
Message: string
}

View file

@ -294,6 +294,43 @@ Setting up your own email server is a bit overkill for what we are trying to ach
#### Amazon Simple Email Service and SNS
Amazon Simple Email Service (SES) has options for email receiving. We can use this to add the email functionality to Omnivore-self hosted.
##### Step 1. Create Identity
Create your identity using Amazon SES. This will be your domain.
![create-identity](../docs/guides/images/ses-add-domain.png)
##### Step 2. Verify the Domain using the CNAME Records.
![Verify Domain](../docs/guides/images/ses-verify.png)
#### Step 3. Add the MX Record
See instructions on how to do that [here](https://docs.aws.amazon.com/ses/latest/dg/receiving-email-mx-record.html)
##### Step 4. Create Email-Receiving Ruleset
![Create Ruleset](../docs/guides/images/ses-verify.png)
![Create Ruleset](../docs/guides/images/sns-define-incoming-rule.png)
##### Step 5. Create SNS Topic Target
![SNS add action](../docs/guides/images/sns-add-actions-sns-menu.png)
![SNS add action publish](../docs/guides/images/sns-add-action-publish.png)
![SNS Create](../docs/guides/images/sns-create-topic.png)
![SNS Topic Menu](../docs/guides/images/sns-topic-menu.png)
![SNS publish](../docs/guides/images/sns-publish-menu.png)
##### Step 6. Setup Subscription
In SNS you must setup a subscription to your Omnivore Host.
![Sns Subscription](../docs/guides/images/sns-create-subscription.png)
##### Step 7. Test by sending email to Omnivore Email
![Email](../docs/guides/images/create-new-email.png)
![Incoming](../docs/guides/images/testing-incoming-email.png)
![Received](../docs/guides/images/received-email.png)
#### Zapier and other Webhook Services.
If you are just looking for a simple way to import emails into your Self Hosted Omnivore Account, you can use a service like Zapier to forward the email into the mail-proxy.

View file

@ -38,6 +38,8 @@ REDIS_URL=redis://redis:6379/0
#MAIL
WATCHER_API_KEY=mail-api-key
LOCAL_EMAIL_DOMAIN=domain.tld
LOCAL_EMAIL_DOMAIN=domain.tld
SNS_ARN=arn_of_sns #for if you use SES and SNS for Email.
# Web
APP_ENV=prod