获取用户的邮箱设置
本文内容
命名空间:microsoft.graph
在用户的 mailboxSettings 中启用、配置或禁用以下一个或多个设置:
自动答复 (收到发件人的电子邮件时自动通知发件人)
dateFormat
delegateMeetingMessageDeliveryOptions
区域设置 (语言和国家/地区)
timeFormat
时区
工作时间
更新用户的首选日期或时间格式时,请分别以短日期 或短时间 格式 指定它 。
更新用户的首选时区时,在 Windows 或 Internet 号码分配机构 (IANA ) 时区 (也称为 Olson 时区) 格式中指定它。 您还可以进一步自定义时区,如下面的示例 2 所示。
权限
要调用此 API,需要以下权限之一。要了解详细信息,包括如何选择权限的信息,请参阅权限 。
权限类型
权限(从最低特权到最高特权)
委派(工作或学校帐户)
MailboxSettings.ReadWrite
委派(个人 Microsoft 帐户)
MailboxSettings.ReadWrite
应用程序
MailboxSettings.ReadWrite
HTTP 请求
PATCH /me/mailboxSettings
PATCH /users/{id|userPrincipalName}/mailboxSettings
可选的查询参数
此方法支持 OData 查询参数 来帮助自定义响应。
名称
类型
说明
Authorization
string
Bearer {token}。必需。
请求正文
在请求正文中,提供应更新的相关属性的值。请求正文中不包括的现有属性将保留其以前的值,或根据对其他属性值的更改重新计算。为了获得最佳性能,不应包括尚未更改的现有值。以下是可写/可更新的属性:
属性
类型
说明
automaticRepliesSetting
automaticRepliesSetting
自动通知发件人有传入电子邮件(包含一封来自已登录用户的邮件)的配置设置。 只能为将来的日期范围设置此类通知。
dateFormat
string
用户邮箱的日期格式。
delegateMeetingMessageDeliveryOptions
delegateMeetingMessageDeliveryOptions
如果用户具有日历代理,则指定代理人、邮箱所有者还是同时接收会议邮件和会议响应。 可取值为:sendToDelegateAndInformationToPrincipal、sendToDelegateAndPrincipal、sendToDelegateOnly。
语言
localeInfo
用户的区域设置信息,包括首选语言和国家/地区。
timeFormat
字符串
用户邮箱的时间格式。
timeZone
string
用户邮箱的默认时区。
workingHours
workingHours
用户工作的小时数、一周的天数和时区。
响应
如果成功,此方法在响应 200 OK 正文中返回 响应代码和 mailboxSettings 对象的更新属性。
错误
将工作时间设置为不适当的值可能会返回以下错误。
应用场景
HTTP 状态代码
错误代码
错误消息
startTime 或 endTime 无效
400
RequestBodyRead
无法将文本“08”转换为预期类型“Edm.TimeOfDay”。
开始时间大于结束时间
400
ErrorInvalidTimeSettings
开始时间应早于结束时间。
daysOfWeek 中的天数无效
400
InvalidArguments
未找到请求值“RandomDay”。
timeZone 无效
400
InvalidTimeZone
提供的时区设置无效。
示例
示例 1
请求
第一个示例通过设置 automaticRepliesSetting 属性的以下属性来启用对日期范围的自动答复:status 、scheduledStartDateTime 和 scheduledEndDateTime 。
PATCH https://graph.microsoft.com/v1.0/me/mailboxSettings
Content-Type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Me/mailboxSettings",
"automaticRepliesSetting": {
"status": "Scheduled",
"scheduledStartDateTime": {
"dateTime": "2016-03-20T18:00:00.0000000",
"timeZone": "UTC"
},
"scheduledEndDateTime": {
"dateTime": "2016-03-28T18:00:00.0000000",
"timeZone": "UTC"
}
}
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var mailboxSettings = new MailboxSettings
{
AutomaticRepliesSetting = new AutomaticRepliesSetting
{
Status = AutomaticRepliesStatus.Scheduled,
ScheduledStartDateTime = new DateTimeTimeZone
{
DateTime = "2016-03-20T18:00:00",
TimeZone = "UTC"
},
ScheduledEndDateTime = new DateTimeTimeZone
{
DateTime = "2016-03-28T18:00:00",
TimeZone = "UTC"
}
},
AdditionalData = new Dictionary<string, object>()
{
{"@odata.context", "https://graph.microsoft.com/v1.0/$metadata#Me/mailboxSettings"}
}
};
var me = new User();
me.MailboxSettings = mailboxSettings;
await graphClient.Me
.Request()
.UpdateAsync(me);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
const mailboxSettings = {
'@odata.context': 'https://graph.microsoft.com/v1.0/$metadata#Me/mailboxSettings',
automaticRepliesSetting: {
status: 'Scheduled',
scheduledStartDateTime: {
dateTime: '2016-03-20T18:00:00.0000000',
timeZone: 'UTC'
},
scheduledEndDateTime: {
dateTime: '2016-03-28T18:00:00.0000000',
timeZone: 'UTC'
}
}
};
await client.api('/me/mailboxSettings')
.update(mailboxSettings);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/mailboxSettings"]]];
[urlRequest setHTTPMethod:@"PATCH"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphMailboxSettings *mailboxSettings = [[MSGraphMailboxSettings alloc] init];
MSGraphAutomaticRepliesSetting *automaticRepliesSetting = [[MSGraphAutomaticRepliesSetting alloc] init];
[automaticRepliesSetting setStatus: [MSGraphAutomaticRepliesStatus scheduled]];
MSGraphDateTimeTimeZone *scheduledStartDateTime = [[MSGraphDateTimeTimeZone alloc] init];
[scheduledStartDateTime setDateTime: "2016-03-20T18:00:00"];
[scheduledStartDateTime setTimeZone:@"UTC"];
[automaticRepliesSetting setScheduledStartDateTime:scheduledStartDateTime];
MSGraphDateTimeTimeZone *scheduledEndDateTime = [[MSGraphDateTimeTimeZone alloc] init];
[scheduledEndDateTime setDateTime: "2016-03-28T18:00:00"];
[scheduledEndDateTime setTimeZone:@"UTC"];
[automaticRepliesSetting setScheduledEndDateTime:scheduledEndDateTime];
[mailboxSettings setAutomaticRepliesSetting:automaticRepliesSetting];
NSError *error;
NSData *mailboxSettingsData = [mailboxSettings getSerializedDataWithError:&error];
[urlRequest setHTTPBody:mailboxSettingsData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
MailboxSettings mailboxSettings = new MailboxSettings();
mailboxSettings.additionalDataManager().put("@odata.context", new JsonPrimitive("https://graph.microsoft.com/v1.0/$metadata#Me/mailboxSettings"));
AutomaticRepliesSetting automaticRepliesSetting = new AutomaticRepliesSetting();
automaticRepliesSetting.status = AutomaticRepliesStatus.SCHEDULED;
DateTimeTimeZone scheduledStartDateTime = new DateTimeTimeZone();
scheduledStartDateTime.dateTime = "2016-03-20T18:00:00";
scheduledStartDateTime.timeZone = "UTC";
automaticRepliesSetting.scheduledStartDateTime = scheduledStartDateTime;
DateTimeTimeZone scheduledEndDateTime = new DateTimeTimeZone();
scheduledEndDateTime.dateTime = "2016-03-28T18:00:00";
scheduledEndDateTime.timeZone = "UTC";
automaticRepliesSetting.scheduledEndDateTime = scheduledEndDateTime;
mailboxSettings.automaticRepliesSetting = automaticRepliesSetting;
graphClient.customRequest("/me/mailboxSettings", MailboxSettings.class)
.buildRequest()
.patch(mailboxSettings);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
响应
该响应包括自动答复的更新设置。 注意:为了提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Me/mailboxSettings",
"automaticRepliesSetting": {
"status": "scheduled",
"externalAudience": "all",
"scheduledStartDateTime": {
"dateTime": "2016-03-20T02:00:00.0000000",
"timeZone": "UTC"
},
"scheduledEndDateTime": {
"dateTime": "2016-03-28T02:00:00.0000000",
"timeZone": "UTC"
},
"internalReplyMessage": "<html>\n<body>\n<p>I'm at our company's worldwide reunion and will respond to your message as soon as I return.<br>\n</p></body>\n</html>\n",
"externalReplyMessage": "<html>\n<body>\n<p>I'm at the Contoso worldwide reunion and will respond to your message as soon as I return.<br>\n</p></body>\n</html>\n"
}
}
示例 2
请求
第二个示例通过将 timeZone 属性设置为 自定义时区 ,为登录用户的工作时间自定义时区。
PATCH https://graph.microsoft.com/v1.0/me/mailboxSettings
Content-Type: application/json
{
"workingHours": {
"endTime" : "18:30:00.0000000",
"daysOfWeek": [
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
],
"timeZone" : {
"@odata.type": "#microsoft.graph.customTimeZone",
"bias":-300,
"name": "Customized Time Zone",
"standardOffset":{
"time":"02:00:00.0000000",
"dayOccurrence":2,
"dayOfWeek":"Sunday",
"month":10,
"year":0
},
"daylightOffset":{
"daylightBias":100,
"time":"02:00:00.0000000",
"dayOccurrence":4,
"dayOfWeek":"Sunday",
"month":5,
"year":0
}
}
}
}
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
var mailboxSettings = new MailboxSettings
{
WorkingHours = new WorkingHours
{
EndTime = new TimeOfDay(18, 30, 0),
DaysOfWeek = new List<DayOfWeek>()
{
DayOfWeek.Monday,
DayOfWeek.Tuesday,
DayOfWeek.Wednesday,
DayOfWeek.Thursday,
DayOfWeek.Friday,
DayOfWeek.Saturday
},
TimeZone = new CustomTimeZone
{
Bias = -300,
Name = "Customized Time Zone",
StandardOffset = new StandardTimeZoneOffset
{
Time = new TimeOfDay(2, 0, 0),
DayOccurrence = 2,
DayOfWeek = DayOfWeek.Sunday,
Month = 10,
Year = 0
},
DaylightOffset = new DaylightTimeZoneOffset
{
DaylightBias = 100,
Time = new TimeOfDay(2, 0, 0),
DayOccurrence = 4,
DayOfWeek = DayOfWeek.Sunday,
Month = 5,
Year = 0
}
}
}
};
var me = new User();
me.MailboxSettings = mailboxSettings;
await graphClient.Me
.Request()
.UpdateAsync(me);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
const options = {
authProvider,
};
const client = Client.init(options);
const mailboxSettings = {
workingHours: {
endTime: '18:30:00.0000000',
daysOfWeek: [
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday'
],
timeZone: {
'@odata.type': '#microsoft.graph.customTimeZone',
bias: -300,
name: 'Customized Time Zone',
standardOffset: {
time: '02:00:00.0000000',
dayOccurrence: 2,
dayOfWeek: 'Sunday',
month: 10,
year: 0
},
daylightOffset: {
daylightBias: 100,
time: '02:00:00.0000000',
dayOccurrence: 4,
dayOfWeek: 'Sunday',
month: 5,
year: 0
}
}
}
};
await client.api('/me/mailboxSettings')
.update(mailboxSettings);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
MSHTTPClient *httpClient = [MSClientFactory createHTTPClientWithAuthenticationProvider:authenticationProvider];
NSString *MSGraphBaseURL = @"https://graph.microsoft.com/v1.0/";
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[MSGraphBaseURL stringByAppendingString:@"/me/mailboxSettings"]]];
[urlRequest setHTTPMethod:@"PATCH"];
[urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
MSGraphMailboxSettings *mailboxSettings = [[MSGraphMailboxSettings alloc] init];
MSGraphWorkingHours *workingHours = [[MSGraphWorkingHours alloc] init];
[workingHours setEndTime:@"18:30:00.0000000"];
NSMutableArray *daysOfWeekList = [[NSMutableArray alloc] init];
[daysOfWeekList addObject: @"Monday"];
[daysOfWeekList addObject: @"Tuesday"];
[daysOfWeekList addObject: @"Wednesday"];
[daysOfWeekList addObject: @"Thursday"];
[daysOfWeekList addObject: @"Friday"];
[daysOfWeekList addObject: @"Saturday"];
[workingHours setDaysOfWeek:daysOfWeekList];
MSGraphTimeZoneBase *timeZone = [[MSGraphTimeZoneBase alloc] init];
[timeZone setBias: -300];
[timeZone setName:@"Customized Time Zone"];
MSGraphStandardTimeZoneOffset *standardOffset = [[MSGraphStandardTimeZoneOffset alloc] init];
[standardOffset setTime:@"02:00:00.0000000"];
[standardOffset setDayOccurrence: 2];
[standardOffset setDayOfWeek: [MSGraphDayOfWeek sunday]];
[standardOffset setMonth: 10];
[standardOffset setYear: 0];
[timeZone setStandardOffset:standardOffset];
MSGraphDaylightTimeZoneOffset *daylightOffset = [[MSGraphDaylightTimeZoneOffset alloc] init];
[daylightOffset setDaylightBias: 100];
[daylightOffset setTime:@"02:00:00.0000000"];
[daylightOffset setDayOccurrence: 4];
[daylightOffset setDayOfWeek: [MSGraphDayOfWeek sunday]];
[daylightOffset setMonth: 5];
[daylightOffset setYear: 0];
[timeZone setDaylightOffset:daylightOffset];
[workingHours setTimeZone:timeZone];
[mailboxSettings setWorkingHours:workingHours];
NSError *error;
NSData *mailboxSettingsData = [mailboxSettings getSerializedDataWithError:&error];
[urlRequest setHTTPBody:mailboxSettingsData];
MSURLSessionDataTask *meDataTask = [httpClient dataTaskWithRequest:urlRequest
completionHandler: ^(NSData *data, NSURLResponse *response, NSError *nserror) {
//Request Completed
}];
[meDataTask execute];
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
MailboxSettings mailboxSettings = new MailboxSettings();
WorkingHours workingHours = new WorkingHours();
workingHours.endTime = new TimeOfDay(0, 0, 0);
LinkedList<DayOfWeek> daysOfWeekList = new LinkedList<DayOfWeek>();
daysOfWeekList.add(DayOfWeek.MONDAY);
daysOfWeekList.add(DayOfWeek.TUESDAY);
daysOfWeekList.add(DayOfWeek.WEDNESDAY);
daysOfWeekList.add(DayOfWeek.THURSDAY);
daysOfWeekList.add(DayOfWeek.FRIDAY);
daysOfWeekList.add(DayOfWeek.SATURDAY);
workingHours.daysOfWeek = daysOfWeekList;
CustomTimeZone timeZone = new CustomTimeZone();
timeZone.bias = -300;
timeZone.name = "Customized Time Zone";
StandardTimeZoneOffset standardOffset = new StandardTimeZoneOffset();
standardOffset.time = new TimeOfDay(0, 0, 0);
standardOffset.dayOccurrence = 2;
standardOffset.dayOfWeek = DayOfWeek.SUNDAY;
standardOffset.month = 10;
standardOffset.year = 0;
timeZone.standardOffset = standardOffset;
DaylightTimeZoneOffset daylightOffset = new DaylightTimeZoneOffset();
daylightOffset.daylightBias = 100;
daylightOffset.time = new TimeOfDay(0, 0, 0);
daylightOffset.dayOccurrence = 4;
daylightOffset.dayOfWeek = DayOfWeek.SUNDAY;
daylightOffset.month = 5;
daylightOffset.year = 0;
timeZone.daylightOffset = daylightOffset;
workingHours.timeZone = timeZone;
mailboxSettings.workingHours = workingHours;
graphClient.customRequest("/me/mailboxSettings", MailboxSettings.class)
.buildRequest()
.patch(mailboxSettings);
有关如何将 SDK 添加 到项目并 创建 authProvider 实例的 详细信息,请参阅 SDK 文档 。
响应
这是一个示例响应。注意:为提高可读性,可能缩短了此处显示的响应对象。
HTTP/1.1 200 OK
Content-type: application/json
{
"@odata.context":"https://graph.microsoft.com/v1.0/$metadata#users('94447c6e-ea4c-494c-a9ed-d905e366c5cb')/mailboxSettings",
"workingHours":{
"daysOfWeek":[
"monday",
"tuesday",
"wednesday",
"thursday",
"friday",
"saturday"
],
"startTime":"09:00:00.0000000",
"endTime":"18:30:00.0000000",
"timeZone":{
"@odata.type":"#microsoft.graph.customTimeZone",
"bias":-200,
"name":"Customized Time Zone",
"standardOffset":{
"time":"02:00:00.0000000",
"dayOccurrence":4,
"dayOfWeek":"sunday",
"month":5,
"year":0
},
"daylightOffset":{
"daylightBias":-100,
"time":"02:00:00.0000000",
"dayOccurrence":2,
"dayOfWeek":"sunday",
"month":10,
"year":0
}
}
}
}