reactivepixel/Max-Bot

Sending Email

Closed this issue · 3 comments

Research and prototype how to send an email message.

The code you create should be a module that other files can require in to utilize the functionality you prototype.

Please provide concise documentation on how to use the module you are creating.

I recommend you ultimately use GMail to send the message, but research this and other options.

I've been running into errors with using Gmail for this. It's something to do with the security. Once I changed the port from 465 to 587 and changed the secure option to false, I got it working. I'm going to create the files now.

Note: It is recommended to use Oauth for this. We will have to use password authentication for now.

Send gmail through Node.js

Before beginning

You must have experience in Node.js. You will install the dependency Nodemailer. This package is great because it has no dependencies other than Node itself. Theoretically, this package will work for more than gmail.

Note: We will create two objects: transporter and mailoptions: name, html, etc...

We will then call the sendmail method of the transporter and pass the mailoptions as an argument to the function.

Installation

Step1

Install the nodemailer dependency into your node server.

npm install nodemailer -S

Step 2

Add your account credentials as variables to your environment config. They should look like this.

ACCOUNT_USERNAME: 'XXXXXXX@gmail.com'
ACCOUNT_PASSWORD: 'XXXXXXX'

Step 3

Add the nodemailer.js file to your project. Copy the attached gist below.

Download this Nodemailer Gist

Step 4

Edit the mailoptions variable to your liking. This variable is the email to be sent to the user. There are more options than needed on nodemailer if needed. For example, you can specify the watchText option which is the text that displays on the watch.

If you have any further questions, please feel free to ask. I will close this issue until then.