mpc-csharp-semantickernel

mpc-csharp-semantickernel

site icon
2025.03.24 2
C#邮件自动化OpenAI 集成开发效率
mpc-csharp-semantickernel 是一个示例项目,展示了如何使用 Microsoft Semantic Kernel 结合 OpenAI 和 Model Context Protocol 的官方 C# SDK。该项目主要用于演示如何通过 C# 和 OpenAI 实现自动化邮件发送功能。
View on GitHub

Overview

基本能力

产品定位

mpc-csharp-semantickernel 是一个示例项目,展示了如何使用 Microsoft Semantic Kernel 结合 OpenAI 和 Model Context Protocol 的官方 C# SDK。该项目主要用于演示如何通过 C# 和 OpenAI 实现自动化邮件发送功能。

核心功能

  1. 使用 OpenAI 的 API 生成文本内容。
  2. 通过 SMTP 邮件服务器发送生成的邮件内容。
  3. 支持自定义邮件接收者列表。

适用场景

  1. 自动化邮件发送:例如自动发送通知、提醒或个性化邮件。
  2. 开发示例:作为开发者的参考项目,了解如何集成 OpenAI 和 SMTP 服务。

工具列表

  1. EmailTool.cs:用于管理邮件接收者列表和发送邮件的工具。
  2. 能力:支持自定义邮件接收者列表,通过 SMTP 服务器发送邮件。

常见问题解答

  1. 如何获取 OpenAI API Key?
  2. 通过 OpenAI 开发者仪表板获取 API Key。
  3. 如何配置 SMTP 服务器?
  4. appsettings.json 中配置 SMTP 服务器的详细信息。
  5. 如何添加邮件接收者?
  6. EmailTool.cs 中更新 emails 字典,添加接收者的名称和邮箱地址。

使用教程

使用依赖

  1. SMTP 邮件服务器:用于发送邮件。
  2. OpenAI API Key:用于生成邮件内容。

安装教程

  1. 从 OpenAI 开发者仪表板获取 API Key。
  2. appsettings.json 中配置 OpenAI API Key 和 SMTP 服务器信息。
  3. WebAppMCPPoc Project 配置示例: json { "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "OpenAI": { "ApiKey": "<yourApiKey>", "ChatModelId" : "gpt-4o-mini" } }
  4. MCPServer Project 配置示例: json { "Logging": { "LogLevel": { "Default": "Information", "Microsoft.AspNetCore": "Warning" } }, "AllowedHosts": "*", "EmailSettings": { "SMTPServer": { "MailPort": "465", "MailServer": "<yourserver.com>", "Sender": "<[email protected]>", "SenderName": "<AIEmailSender>", "Password": "<EmailPassword>", "Username": "<EmailUsername>" } } }
  5. EmailTool.cs 中更新 emails 字典,添加邮件接收者。
  6. 运行项目,默认启动地址为 http://localhost:5109

调试方式

  1. 使用 Postman 发送请求示例:
  2. 请求方法:POST
  3. 请求地址:https://localhost:7113/chat
  4. 请求体: json { "text": "send and email to aFriend and tell him that you are an ai in 250 words. Tell him you're using C# to do this.." }
  5. 检查邮件是否成功发送到指定的接收者邮箱。

许可证

该项目遵循 MIT 开源许可条款,请参阅 MIT 了解完整条款。