0%

Google Apps Mail로 정적 HTML 폼 데이터를 메일로 보내기

사실 Gmail API를 사용해서 메일을 보내면 되는 태스크인데, api에 종속되지 않고 메일을 보낼 수 있는 방법이어서 시도해봤다. 서버 없이 프론트에서 form을 이용해 메일을 보낼 수 있는 방법이라 알아두면 유용할 것 같다.

Google apps script

본인 계정의 지메일로 구글 스프레드 시트를 deploy 함. (구글 드라이브에서 확인 가능)

https://docs.google.com/spreadsheets/… → Tools 탭 → Script Editor

* 테스트 후 Manage Deployment 에서 권한 Only Myself 로 설정! *


  • 보내는 사람: Google Apps 를 deploy한 사람

  • 받는 사람: mailData.receiver (내 form의 name="receiver" 이 받는 사람이기 때문)

    it defaults to the email provided by the form’s data attribute

  • var mailData = e.parameters === FormData body

    • e : formData

      e is the data received from the POST

    • e.parameters === mailData : formData.data

      shorter name for form data

    1
    2
    3
    4
    5
    6
    7
    8
    9
    /*

    formData // e
    data // e.parameters
    {"receiver": "", ...}

    */

    "data":"{\\"receiver\\":[\\"aaa@gmail.com\\"],\\"title\\":[\\"z\\"],\\"message\\":[\\"q\\"]}"

위는 내 폼 형식에 맞게 중요한 부분만 적어두었는데, 단계별로 진행해보고 싶다면 밑 레퍼런스를 참고하면 된다.

Reference

내 홈페이지에 이메일 보내기 기능 넣기! | form태그에서 이메일 전송 기능 구현하기 | 서버없이! html과 javascript로만! | 내 html에 추가하기 | html 이메일 보내기 기능 | 웹페이지에 이메일 기능 넣..

정적 HTML form태그에서 메일보내기 : Google Apps Mail

GitHub - dwyl/learn-to-send-email-via-google-script-html-no-server: An Example of using an HTML form (e.g: “Contact Us” on a website) to send Email without a Backend Server (using a Google Script) perfect for static websites that need to collect data.