An Azure server-less function written in JavaScript (Node) for handling contact forms on your personal website
- Accept POST requests with user input from the front-end form
- Validate the user input against few predefined rules (will be covered in details below)
- Sanitise the user input so it does not contain any special character that may lead to injections
- Interact with Microsoft Graph REST API to forward the sender contact info and message to you as an email
- Send a response back to the front-end indicating the result of this process (success or fail)
HTML Input name | HTML Input type | Input criteria | Max input length | Mandatory field |
---|---|---|---|---|
name | text | Any alphabetic character, and whitespace | 40 characters | Yes |
Any valid email address | Not applicable | Yes | ||
subject | text | No restrictions | 50 characters | Yes |
msg | textarea | No restrictions | 800 characters | Yes |
- An Azure account with active subscription (to deploy this function)
- An active work or school Microsoft account with global admin access to Azure Active Directory (to set up Graph API access key)
- Register this function as a new application and acquire the client secret within AAD
- Provide your Client ID, the acquired Client secret, the Tenant ID of your organisation, to your function app as environment variables via Azure Portal
- Provide the sender (this function) and recipient (yourself) email addresses, also as environment variables, note the sender email has to be within your organisation, but the recipient email can be any service (personal Outlook, Gmail, Yahoo etc.)
- These environment variables should be named as:
CLIENT_ID
,CLIENT_SECRET
,TENANT_ID
,SENDER_EMAIL_ADDR
andRECIPIENT_EMAIL_ADDR
respectively
- Getting started with Azure Functions
- Manage your function app - Work with application settings
- Register an application with the Microsoft identity platform
- Microsoft Graph REST API v1.0 endpoint reference
Copyright © 2022 Bread-John. All Rights Reserved. Licensed under GNU General Public License v3.0 (see "License")