Giter Club home page Giter Club logo

valentine-mail's Introduction

Valentine's Day Mail

Alt text Alt text Alt text

วัตถุประสงค์

เพื่อบอกรักแฟนผ่าน mail ที่สวยงามในวัน valentine และส่งความรักให้คนพิเศษที่เรารัก

characteristics ของแอปพลิเคชัน

  • สามารถส่งอีเมล์ได้โดยใส่ที่อยู่อีเมล์ของผู้ส่งและผู้รับ, หัวข้อเรื่อง และข้อความ
  • แสดงข้อความแจ้งเตือนด้วย http status เมื่อส่งอีเมล์สำเร็จหรือไม่สำเร็จ

การใช้งานของ Transport Layer

ใช้ Transport Layer แบบ TCP (Transmission Control Protocol) เนื่องจาก TCP มีความเสถียรและนิ่งที่สูง และเหมาะสมสำหรับการส่งข้อมูลที่ต้องการความเชื่อถือ เช่น เมล

// สร้าง Nodemailer transporter object พร้อมกับการกำหนดค่า SMTP
const transporter = nodemailer.createTransport({
  host: "smtp.gmail.com", // ใช้ Gmail SMTP server
  secure: false, // ไม่ต้องการ TLS/SSL
  ignoreTLS: false, // ไม่ต้องการเพิ่มโมดูล TLS
  auth: {
    user: "[email protected]", // ที่อยู่อีเมลผู้ใช้ Gmail
    pass: process.env.GMAIL_APP_PASSWORD as string, // รหัสแอป Gmail ที่ได้รับจาก environment variables
  },
});

// ฟังก์ชันสำหรับส่งอีเมล โดยใช้ transporter
const sendMail = (
  mailOptions: nodemailer.SendMailOptions // ตัวเลือกการส่งอีเมลที่จะส่งไปยังฟังก์ชัน sendMail
): Promise<SentMessageInfo> => {
  // ส่ง Promise ที่ resolve กับข้อมูลข้อความที่ส่งไป หรือ reject ด้วยข้อผิดพลาด
  return new Promise((resolve, reject) => {
    // ใช้ transporter เพื่อส่งอีเมล ด้วย mailOptions ที่ให้ไว้
    transporter.sendMail(mailOptions, (error, info) => {
      if (error) {
        // หากเกิดข้อผิดพลาด  reject Promise ด้วย error object
        reject(error);
      } else {
        // หากสำเร็จ resolve Promise ด้วยข้อมูลข้อความที่ส่งไป
        resolve(info);
      }
    });
  });
};

การออกแบบ Application-layer Protocol

  • ใช้ SMTP ในการส่งอีเมล โดยใช้ Nodemailer เป็นโมดูลที่ใช้ส่งอีเมล และใช้ Gmail SMTP server เป็น SMTP server เนื่องจาก Gmail SMTP server มีความเสถียรและนิ่งที่สูง และเหมาะสมสำหรับการส่งข้อมูลแบบเชื่อมต่อที่ต้องการความเชื่อถือและความแม่นยำ
  • ใช้ DNS ในการแปลงชื่อโดเมนเป็นที่อยู่ IP ของเซิร์ฟเวอร์ เนื่องจากโปรแกรมนี้ใช้ Gmail SMTP server ซึ่งมีที่อยู่ IP คงที่ และใช้ชื่อโดเมนเป็น smtp.gmail.com
  • ใช้ HTTP ในการสื่อสารระหว่าง Client และ Server เนื่องจาก HTTP มีความเป็น stateless และเป็นโปรโตคอลที่มีความเป็นที่นิยมในการสื่อสารระหว่าง Client และ Server ในปัจจุบัน

รูปแบบข้อความ (Message Format)

  • SEND_MAIL: ข้อความสำหรับส่งอีเมล์ ประกอบด้วยข้อมูลเช่น ผู้ส่ง, ผู้รับ, หัวข้อเรื่อง, และข้อความ

    class Mail {
      constructor(
        public from: string,
        public to: string,
        public subject: string,
        public message: string
      ) {}
    }
  • NOTIFICATION: ข้อความแจ้งเตือนการส่งอีเมล์สำเร็จหรือไม่สำเร็จ สถานะ (Status Code, Status Phrase)

    try {
      const info = await sendMail(mailOptions);
      res.status(200).send("Email sent: " + info.response);
      console.log("Email sent: " + info.response);
    } catch (error: any) {
      console.error(error);
      res.status(500).send(error.toString());
    }

ชื่อ Protocol: "SMTP ส่งรักส่งเลิฟ"

การใช้งานด้วย docker

  1. Clone repository
    git clone https://github.com/ong22280/simple-mail-wireshark.git
  2. กำหนดค่าตัวแปร environment ในไฟล์ .env
    cd simple-mail-wireshark/server
    cp .env.example .env
    แก้ไขไฟล์ .env
    # .env
    GMAIL_APP_PASSWORD=your_gmail_app_password
  3. Run docker-compose
    cd simple-mail-wireshark
    docker-compose up
  4. เข้าถึงแอปพลิเคชันผ่าน URL: http://localhost:3001 หรือ https://mail-client-ong22280.vercel.app/

การใช้งานหากไม่ใช้ docker

  1. Clone repository
    git clone https://github.com/ong22280/simple-mail-wireshark.git
  2. ติดตั้ง dependencies ของ client และ server
    cd simple-mail-wireshark/client
    npm install
    cd simple-mail-wireshark/server
    npm install
  3. กำหนดค่าตัวแปร environment ในไฟล์ .env
    cd simple-mail-wireshark/server
    cp .env.example .env
    แก้ไขไฟล์ .env
    # .env
    GMAIL_APP_PASSWORD=your_gmail_app_password
  4. เริ่มต้นแอปพลิเคชัน
    cd simple-mail-wireshark/server
    npm start
    cd simple-mail-wireshark/client
    npm run dev
  5. เข้าถึงแอปพลิเคชันผ่าน URL: http://localhost:3001 หรือ https://mail-client-ong22280.vercel.app/

valentine-mail's People

Contributors

ong22280 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.