我需要编写一个.NET Core控制台应用程序,它可以从Office 365帐户获取一些电子邮件。
是否有可能使用电子邮件和密码访问Office 365 API而无需任何弹出窗口和用户界面?
我尝试了一种在Azure Active Directory中注册应用程序的解决方案,但它并不适合我的目的,因为登录的用户必须与特定的AAD帐户相关联。
我在StuckOverflow上发现了这样的问题,但它们都与旧版本的API和旧方法有关。
我花了4天时间寻找解决方案,阅读了大量文档,但我仍然停滞不前。
以下示例是使用Exchange API,而不是Office 365 API。
这是登录Office 365的Exchange服务器并将日历条目发送到电子邮件地址的示例。
//Connect to exchange
var ewsProxy = new ExchangeService(ExchangeVersion.Exchange2013);
ewsProxy.Url = new Uri("https://outlook.office365.com/ews/exchange.asmx");
//Create the meeting
var meeting = new Appointment(ewsProxy);
ewsProxy.Credentials = new NetworkCredential(_Username, _Password);
meeting.RequiredAttendees.Add(_Recipient);
// Set the properties on the meeting object to create the meeting.
meeting.Subject = "Meeting";
meeting.Body = "Please go to the meeting.";
meeting.Start = DateTime.Now.AddHours(1);
meeting.End = DateTime.Now.AddHours(2);
meeting.Location = "Location";
meeting.ReminderMinutesBeforeStart = 60;
// Save the meeting to the Calendar folder and send the meeting request.
meeting.Save(SendInvitationsMode.SendToAllAndSaveCopy);
有关更多信息,请参阅以下链接:
使用Office 365 REST API而不使用UI
获取Office 365 API访问令牌,无需用户交互