基本能力
产品定位
mpc-csharp-semantickernel 是一个示例项目,展示了如何使用 Microsoft Semantic Kernel 结合 OpenAI 和 Model Context Protocol 的官方 C# SDK。该项目主要用于演示如何通过 C# 和 OpenAI 实现自动化邮件发送功能。
核心功能
- 使用 OpenAI 的 API 生成文本内容。
- 通过 SMTP 邮件服务器发送生成的邮件内容。
- 支持自定义邮件接收者列表。
适用场景
- 自动化邮件发送:例如自动发送通知、提醒或个性化邮件。
- 开发示例:作为开发者的参考项目,了解如何集成 OpenAI 和 SMTP 服务。
工具列表
- EmailTool.cs:用于管理邮件接收者列表和发送邮件的工具。
- 能力:支持自定义邮件接收者列表,通过 SMTP 服务器发送邮件。
常见问题解答
- 如何获取 OpenAI API Key?
- 通过 OpenAI 开发者仪表板获取 API Key。
- 如何配置 SMTP 服务器?
- 在
appsettings.json
中配置 SMTP 服务器的详细信息。 - 如何添加邮件接收者?
- 在
EmailTool.cs
中更新emails
字典,添加接收者的名称和邮箱地址。
使用教程
使用依赖
- SMTP 邮件服务器:用于发送邮件。
- OpenAI API Key:用于生成邮件内容。
安装教程
- 从 OpenAI 开发者仪表板获取 API Key。
- 在
appsettings.json
中配置 OpenAI API Key 和 SMTP 服务器信息。 - WebAppMCPPoc Project 配置示例:
json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"OpenAI": {
"ApiKey": "<yourApiKey>",
"ChatModelId" : "gpt-4o-mini"
}
} - MCPServer Project 配置示例:
json
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*",
"EmailSettings": {
"SMTPServer": {
"MailPort": "465",
"MailServer": "<yourserver.com>",
"Sender": "<sender@youremail.com>",
"SenderName": "<AIEmailSender>",
"Password": "<EmailPassword>",
"Username": "<EmailUsername>"
}
}
} - 在
EmailTool.cs
中更新emails
字典,添加邮件接收者。 - 运行项目,默认启动地址为
http://localhost:5109
。
调试方式
- 使用 Postman 发送请求示例:
- 请求方法:
POST
- 请求地址:
https://localhost:7113/chat
- 请求体:
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.."
} - 检查邮件是否成功发送到指定的接收者邮箱。