> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mailofly.com/llms.txt
> Use this file to discover all available pages before exploring further.

# AI Tools

> How to use Mailofly with OpenAI, Anthropic Claude, and LangChain function calling.

# AI Tools & Function Calling

You can give LLMs (like OpenAI GPT-4o, Anthropic Claude 3.5 Sonnet, or Gemini) the ability to send emails and inspect delivery statuses through structured tool/function calling.

***

## OpenAI Function Calling Example

Define the sending tool schema:

```typescript theme={null}
import OpenAI from "openai";
import { Mailofly } from "mailofly";

const openai = new OpenAI();
const mailofly = new Mailofly(process.env.MAILOFLY_API_KEY!);

const emailTools: OpenAI.ChatCompletionTool[] = [
  {
    type: "function",
    function: {
      name: "send_email",
      description: "Send an email to a user via Mailofly.",
      parameters: {
        type: "object",
        properties: {
          to: { type: "string", description: "Recipient email address" },
          subject: { type: "string", description: "Subject line of the email" },
          body: { type: "string", description: "HTML content of the email" },
        },
        required: ["to", "subject", "body"],
      },
    },
  },
];
```

### Executing the Function Call

```typescript theme={null}
async function handleToolCall(toolCall: OpenAI.ChatCompletionMessageToolCall) {
  if (toolCall.function.name === "send_email") {
    const args = JSON.parse(toolCall.function.arguments);
    const result = await mailofly.emails.send({
      from: "AI Assistant <assistant@yourdomain.com>",
      to: args.to,
      subject: args.subject,
      html: args.body,
    });
    return JSON.stringify(result);
  }
}
```


## Related topics

- [MCP Tools Reference](/mcp-server/tools.md)
- [MCP Server Guides](/guides/ai/mcp-ai-guides.md)
- [Agent Skills](/guides/ai/agent-skills.md)
- [MCP Quickstart](/mcp-server/quickstart.md)
- [MCP Server](/mcp-server/introduction.md)
