Gmail Organization Invitation API

import os
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from fastapi import FastAPI
from pydantic import BaseModel
import uvicorn

app = FastAPI()

class Invitation(BaseModel):
    recipient_email: str
    inviter_email: str
    organization_name: str
    invitation_link: str"/send_invitation")
def send_invitation(invitation: Invitation):
    # TODO: Replace with your Gmail account details
    gmail_user = os.environ['GMAIL_USER']
    gmail_password = os.environ['GMAIL_PASSWORD']

    msg = MIMEMultipart('alternative')

About this template

This app is an API that sends an invitation email from a Gmail account with 2FA enabled. It accepts various inputs to generate a personalized invitation email based on the name of the email of the person being invited, the email who invited the person and the name of the organisation and an invitation link.

Introduction to Gmail Organization Invitation API Template

Welcome to the step-by-step guide on how to use the Gmail Organization Invitation API Template. This template allows you to send personalized invitation emails to potential members of your organization. The email is sent through a Gmail account with 2FA enabled, and the API accepts various inputs to generate the invitation. Let's get started with how to set up and use this template effectively.

Start with this Template

To begin using this template, click on the "Start with this Template" button. This will initialize the template within the Lazy platform, allowing you to customize it according to your needs.

Environment Secrets

Before you can send out invitations, you need to set up your Gmail account details as environment secrets. This is crucial for the API to access your Gmail account and send emails. Here's how to set them up:

  • Locate the Environment Secrets tab within the Lazy Builder interface.
  • Create two new secrets: one named 'GMAIL_USER' and another named 'GMAIL_PASSWORD'.
  • For 'GMAIL_USER', enter your Gmail email address.
  • For 'GMAIL_PASSWORD', enter the password for your Gmail account. If you have 2FA enabled, you will need to generate an app-specific password to use here.

Remember, these credentials are sensitive, and Lazy will keep them secure as environment secrets.

Using the Test Button

Once you have set up your environment secrets, you can test the functionality of your app. Click the "Test" button to begin the deployment of the app and launch the Lazy CLI. If the code requires any user input, you will be prompted to provide it through the Lazy CLI.

After testing, if your app uses an API, Lazy will provide you with a dedicated server link to use the API. Since this template uses FastAPI, you will also receive a link to the API documentation, which can be very helpful for understanding the available endpoints and how to interact with them.

Sample API Request and Response

To send an invitation using the API, you will make a POST request to the "/send_invitation" endpoint with the required information. Here's a sample request:

POST /send_invitation
Content-Type: application/json

{ "recipient_email": "", "inviter_email": "", "organization_name": "Your Organization", "invitation_link": "" }

Upon a successful request, you will receive a confirmation in the Lazy CLI that the email has been sent. If there is an issue, you will receive an error message detailing what went wrong.

By following these steps, you can easily set up and use the Gmail Organization Invitation API Template to send out personalized invitations to join your organization. Remember to handle your Gmail credentials securely and enjoy the convenience of automating your invitation process.

Last published
June 15, 2024

More templates like this

PDF Data Extraction and Excel Transfer

An app for extracting name, phone number, and email data from PDF files and transferring it to Excel.


sign in with google

This template enhances the login and profile display functionality by giving the user a quick and easy sign in option using their own google accounts

Google Sheets

GPT-4 Exam Generator

This app uses GPT-4 to generate a PDF of a new exam based on an uploaded PDF of a past exam.

Gmail Organization Invitation API