如何使用 ASP.NET Core 将 Outlook 电子邮件数据存储到数据库中

问题描述 投票:0回答:1

我必须使用 ASP.NET Core 将触发到我的组织电子邮件 ID 的 Outlook 电子邮件数据(例如发件人 ID、收件人 ID、电子邮件正文和附件)存储在 SQL Server 数据库中。

您能建议一下如何做吗?我在谷歌上检查了同样的事情没有得到预期的结果。

asp.net-core outlook-restapi
1个回答
0
投票

您可以尝试以下步骤使用asp.net core将outlook电子邮件存储在sql数据库中:

1) 使用 Microsoft Graph API 访问 Outlook 电子邮件。转到 Azure 门户并注册您的应用程序以获取客户端 ID 和密钥。

2) 使用 OAuth 2.0 验证您的应用程序并请求访问用户的 Outlook 帐户。

var cca = ConfidentialClientApplicationBuilder.Create(clientId)
    .WithClientSecret(clientSecret)
    .WithAuthority(new Uri(authority))
    .Build();

3)使用访问令牌,向 Graph API 发出请求以获取电子邮件。

GraphServiceClient graphClient = new GraphServiceClient(new DelegateAuthenticationProvider((requestMessage) =>
{
    requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", accessToken);
    return Task.CompletedTask;
}));

var messages = await graphClient.Me.Messages
    .Request()
    .GetAsync();

4) 创建 SQL Server 数据库和表,用于存储电子邮件数据、发件人、收件人和附件。

5)安装 Entity Framework Core 并使用它在数据库中存储数据。

public class EmailContext : DbContext
{
    public DbSet<Email> Emails { get; set; }
    // Other DbSet properties for senders, recipients, and attachments
}

public class Email
{
    public string SenderId { get; set; }
    public string RecipientId { get; set; }
    // Other properties for the email body and attachments
}

注意:根据组织的政策和任何相关的数据保护法规,安全地处理任何敏感数据。确保所有敏感数据都已加密,并且您遵循保护应用程序安全的最佳实践。

© www.soinside.com 2019 - 2024. All rights reserved.