Giter VIP home page Giter VIP logo

sendgrid-with-node.js's Introduction

SendGrid-with-Node.js

ส่งเมลด้วย SendGrid และ Node.js

ก่อนอื่นเลย เราต้องไป sign up ที่เว็บ app.sendgrid.com เพื่อที่เราจะได้เข้าไปสร้าง API Key

Create API Key

log in to app.sendgrid.com > go to Settings > API Keys > Create API Key
ตั้งชื่อ API Key กดเลือก Restricted Access และเลื่อนลงไปตรงเมนู Mail Send กดลูกศรลง แล้วกดตรงวงกลมขวาสุดของ Mail Send เสร็จแล้วกด Create & View
หลังจากนั้นจะมี API Key ขึ้นมา ให้เราก็อป key นั้นไว้ !!อย่าลืมก็อป key ไว้!!

Create Folder

open terminal >
  mkdir FolderName  
  cd FolderName 

Install npm

 npm init --yes 

Install library

 npm install @sendgrid/mail

วิธีเก็บ API Key ใน environment

 echo "export SENDGRID_API_KEY='API Key ที่เราเพิ่งก็อปมา'" > sendgrid.env
 echo "sendgrid.env" >> .gitignore
 source ./sendgrid.env
สร้างไฟล์ในโฟลเดอร์ที่เราเพิ่งสร้างขึ้น ในที่นี้เราจะให้ไฟล์ชื่อว่า sendGrid.js
const Mail = require("@sendgrid/mail");
Mail.setApiKey(process.env.SENDGRID_API_KEY);
const message = {
    to: "[email protected]",
    from: "[email protected]",
    subject: "Sending mail with SendGrid",
    text: "This email is created with Node.js",
    html: "<strong>This email is created with Node.js</strong>",
};
Mail.send(message);
ซึ่งเราสามารถใส่ style หรือ แก้ไขเนื้อหาภายใน mail โดยใช้ HTML tag
เมื่อเสร็จแล้วก็ save file และกลับไปที่ terminal เพื่อ run โปรแกรม
node sendGrid.js
ตอนนี้เมลจะถูกส่งไปแล้วให้เราลองไปเช็คใน inbox ของผู้รับ หรือไปเช็คใน account ของเราที่ app.sendgrid.com ตรง Activity

ศึกษาเพิ่มเติมได้ในวิดีโอนี้ https://www.youtube.com/watch?v=s2bzUzHeSVw

หรือใน Setup Guide > Integrate using our Web API or SMTP relay > Web API > Node.js

sendgrid-with-node.js's People

Contributors

siriyas avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.