Mail Server Solution(3)SendGrid

Mail Server Solution(3)SendGrid

1. Set Up ngrok
https://ngrok.com/

Get the file from here https://dl.ngrok.com/ngrok_2.0.19_darwin_amd64.zip
Unzip the file and copy that to working directory, add it to the path.

This Command will verify if it is working
> ngrok -help

Command to Start
> ngrok http localhost:3000
Tunnel Status                 online                                                                                                      
Version                       2.0.19/2.0.19                                                                                              
Web Interface                 http://127.0.0.1:4040                                                                                      
Forwarding                    http://503def19.ngrok.io -> localhost:3000                                                                  
Forwarding                    https://503def19.ngrok.io -> localhost:3000                                                                
                                                                                                                                          
Connections                   ttl     opn     rt1     rt5     p50     p90                                                                 
                              0       0       0.00    0.00    0.00    0.00

This will open a tunnel from the public URL to your localhost 3000 for testing purpose.

2. Set Up the Sample Codes
Create a Free account on app.sendgrid.com
https://github.com/sendgrid/sendgrid-parse-api-example  nodeJS
https://github.com/Ziggeo/php-sendgrid-parse PHP

Go to the pages to set up the email forwarding on SendGrid
https://app.sendgrid.com/settings/parse
Add the domain name and forward URL there. I am using http://requestb.in/1gkr1qv1 for testing.

Adding the MX record to my domain name.
MX  TTL - default (1 hour) - 10 mx.sendgrid.net.

Wait for 1 hour and Send the Email to my domain name.

I setup my domain name in both of these 2 places
https://portal.dynect.net/
http://www.networksolutions.com/

It works after few hours.

Here is the PHP solution(It seems too old.)
https://github.com/sendgrid/sendgrid-parse-demo

Here is the NODEJS solution
https://github.com/sendgrid/sendgrid-parse-api-example

Download the sample project NODEJS
> git clone https://github.com/sendgrid/sendgrid-parse-api-example.git

Change the configuration file
> mv .env.example .env
Change the content their to replace the username and password from SendGrid

Compile
> npm install

Start the Service
> node app.js

Verify if the application is running, should return 200
> curl -I -X POST http://localhost:3000/inbound

Use ngrok to get a public access
> ngrok http 0.0.0.0:3000

Then we will have something like
> curl -I -X POST http://f7df8a18.ngrok.io/inbound

Visit this page to watch the status
http://localhost:4040/inspect/http

You can check the activity on SendGrid
https://app.sendgrid.com/email_activity?

3. Understand the Sample NODEJS Codes
dotenv
https://github.com/motdotla/dotenv

HAPI - similar to ExpressJS
http://hapijs.com/

There is nothing special there, from my understanding, we just directly get the request payload and we get the attachments and attachment1, attachment2, attachment3 ...

References:
Mail Server Solution 1 & 2
http://sillycat.iteye.com/blog/2228923
http://sillycat.iteye.com/blog/2229222

Some Demos and Documents
https://sendgrid.com/
https://sendgrid.com/docs/API_Reference/Webhooks/parse.html
https://sendgrid.com/blog/sendgrids-parse-api-parsing-incoming-email-is-now-faster-and-easier/
https://sendgrid.com/blog/test-webhooks-ngrok/  test sendgrid with ngrok
https://github.com/sendgrid/sendgrid-parse-api-example
https://github.com/sendgrid/sendgrid-parse-demo
https://github.com/phpmasterdotcom/HandleEmailWithSendGrid
https://github.com/theycallmeswift/playlist.sendgriddemos.com

你可能感兴趣的:(server)