Files
langchain/docs/modules/utils/examples/gmail.ipynb
T

2.3 KiB

Gmail Toolkit

The Gmail Toolkit allows you to create drafts, send email, and search for messages and threads using natural language.

As a prerequisite, you will need to register with Google and generate a credentials.json file in the directory where you run this loader. See here for instructions.

This example goes over how to use the Gmail Toolkit:

In [ ]:
from langchain.llms import OpenAI
from langchain.agents.agent_toolkits.gmail.base import create_gmail_agent
import json

llm = OpenAI(verbose=True)
gmail_agent = create_gmail_agent(llm=llm, sender_name="Alice", verbose=True)
In [ ]:
command = "search for all messages during november 2022"
output = gmail_agent.run(command)

messages = json.loads(output)

print("Messages:")
for message in messages:
  print(f"{message['id']}: {message['snippet']}")

id = messages[0]["id"]

command = f"get the body for message id {id}"

output = gmail_agent.run(command)

print(f"Message body: {output}")
In [ ]:
command = "create a draft email to bob@example.com explaining why I can't make the meeting next week."
output = gmail_agent.run(command)

print(output)