aws-receive-email
v1.0.5
Published
Helps you to retrieve emails from S3 bucket
Downloads
15
Readme
AWS EMAIL RECEIVER
In order to receive emails, you should follow the instruction below
Installation
npm install aws-receive-email
Usage
const AWSEmailReceiver = require('email-receive');
AWSEmailReceiver.init(app,{"bucket":"","accessKeyId":"","secretAccessKey":""});
AWSEmailReceiver.emailReceived.subscribe(data=>{
// console.log(data);
AWSEmailReceiver.readEmail(data.to,data.mailId)
.then(email => {
console.log(email);
})
.catch(err => {
console.log(err);
});
});
DELETING EMAIL
AWSEmailReceiver.deleteEmail(data.to,data.mailId)
.then(email => {
console.log(email);
})
.catch(err => {
console.log(err);
});
EMAIL DATA
mail object
Parsed mail* object has the following properties
- headers – a Map object with lowercase header keys
- subject is the subject line (also available from the header mail.headers.get(‘subject’))
- from is an address object for the From: header
- to is an address object for the To: header
- cc is an address object for the Cc: header
- bcc is an address object for the Bcc: header (usually not present)
- date is a Date object for the Date: header
- messageId is the Message-ID value string
- inReplyTo is the In-Reply-To value string
- reply-to is an address object for the Cc: header
- references is an array of referenced Message-ID values
- html is the HTML body of the message. If the message included embedded images as cid: urls then these are all replaced with base64 formatted data: URIs
- text is the plaintext body of the message
- textAsHtml is the plaintext body of the message formatted as HTML
- attachments is an array of attachments
address object
Address objects have the following structure:
value an array with address details
- name is the name part of the email/group
- address is the email address
- group is an array of grouped addresses
text is a formatted address string for plaintext context
html is a formatted address string for HTML context
AWS SETUP
- Login AWS console
- Open SES
- Click on "Rule Sets" below the "Email Receiving" section on the left menu
- Enter the rule set name
- Select the created rule set
- Click on "Create Rule" button on the opened window
- Enter the recipient email
- Once entered it will ask you to confirm domain by entering confirmation DNS record and MX record pointing to the amazon
- Once confirmation and MX record is completed you will see a verified sign beside the entered email
- Click on "Next" button bottom right-hand side of the screen to continue setting up the action
- From the dropdown of "Add action" select the "S3"
- Once you select "S3" it will show you different fields to fill
- Create a unique bucket name
- Enter a prefix (I use the same as email generally)
- Select and SNS (if don't have any follow below to create one)
- Find SNS service section
- Click on "Topics" from the left menu then click on the "Create Topic" button
- Give your topic a proper name and display name
- After the topic created select your topic and click on the "Create Subscription" button from the opened window
- On this screen select HTTP or HTTPS from the protocol
- Enter the main domain you are going to run the "aws-receive-email" module and add the "/aws-email-receiver" router to the URL it should look something like this (http://example.com/aws-email-receiver)
- Once you click on "Create subscription" it will send a post request to that URL, if the app was already running with the module, it should verify subscription right away, otherwise; once you placed the app on the correct URL, you can select the subscription and click on "Request Confirmation" to trigger submission of SubscriptionConfirmation notification
- Once all setup completed on SES and SNS you can send a test email to receive a detail of email on your application and emails are stored on s3, there is also a function to delete the email as well.