You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

基于Microsoft Graph API的代发邮件.NET实现方案验证

使用Microsoft Graph API实现代发邮件的.NET方案验证

我们公司采用Microsoft Graph API实现邮件管理,有以下业务需求:

  • 使用it@company.com这类账号完成登录
  • 以sales@company.com账号代发邮件
  • 邮件对外显示为从salesPerson@company.com员工账号发出,同时需要将邮件保存至sales@company.com的已发送文件夹

注:Azure/Exchange相关权限由客户自行配置,本次仅聚焦.NET代码实现部分。我已完成一个可行方案,现在希望找到更多同类实现方案来验证合理性。

以下是我编写的概念验证代码:

发送邮件方法

public async Task SendEmail(string recipient, string sender, string subject, string body)
{
    GraphServiceClient graphServiceClient = await GetClient();

    await graphServiceClient.Users["sales@company.com"].SendMail.PostAsync(GetBody(recipient, sender, subject, body));
}

构建邮件对象方法

private static SendMailPostRequestBody GetBody(string recipient, string sender, string subject, string body)
{
    return new SendMailPostRequestBody
    {
        Message = new Message
        {
            Subject = subject,
            Body = new ItemBody
            {
                ContentType = BodyType.Text,
                Content = body,
            },
            ToRecipients = new List<Recipient>
            {
                new Recipient
                {
                    EmailAddress = new EmailAddress
                    {
                        Address = recipient,
                    }
                }
            },
            From = new Recipient
            {
                EmailAddress = new EmailAddress
                {
                    Address = "salesPerson@company.com"
                },
            }
        },
        SaveToSentItems = true,
    };
}

内容的提问来源于stack exchange,提问作者Lars Nijholt

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 22:12:06