基于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
相关产品推荐
相关产品推荐

