private string GetBody(TeamMailboxNotificationType type) { string text = string.Empty; string text2 = this.tm.DisplayName; text2 = text2.Replace("<", "<"); text2 = text2.Replace(">", ">"); string str; if (this.tm.SharePointUrl == null) { str = ServerStrings.TeamMailboxMessageNotConnectedToSite; } else { string str2 = this.tm.SharePointUrl.ToString(); str = TeamMailboxNotificationHelper.GetLink(this.tm.SharePointUrl, str2); } string link = TeamMailboxNotificationHelper.GetLink("mailto:" + this.tmSmtpAddress, this.tmSmtpAddress); switch (type) { case TeamMailboxNotificationType.Closed: text = string.Format("<P>{0}</P>", ServerStrings.TeamMailboxMessageClosedBodyIntroText); text += string.Format("<P><B>{0}</B></P>\r\n <UL>\r\n <LI>{1}</LI>\r\n <LI>{2}</LI>\r\n <LI>{3}</LI>\r\n </UL>", new object[] { ServerStrings.TeamMailboxMessageWhatYouCanDoNext, ServerStrings.TeamMailboxMessageNoActionText, ServerStrings.TeamMailboxMessageReactivatingText, ServerStrings.TeamMailboxMessageLearnMore + TeamMailboxNotificationHelper.GetLink(TeamMailboxNotificationHelper.HelpLinkReactivateClosedTeamMailboxes, ServerStrings.TeamMailboxMessageReopenClosedSiteMailbox) }); text += string.Format("<P><B>{0}</B></P>\r\n <UL>\r\n <LI>{1}</LI>\r\n <LI>{2}</LI>\r\n </UL>", ServerStrings.TeamMailboxMessageSiteAndSiteMailboxDetails, ServerStrings.TeamMailboxMessageGoToTheSite + str, ServerStrings.TeamMailboxMessageSiteMailboxEmailAddress + link); break; case TeamMailboxNotificationType.Reactivated: text = string.Format("<P>{0}</P>", ServerStrings.TeamMailboxMessageReactivatedBodyIntroText); text += string.Format("<P><B>{0}</B></P>\r\n <UL>\r\n <LI>{1}</LI>\r\n <LI>{2}</LI>\r\n </UL>", ServerStrings.TeamMailboxMessageWhatYouCanDoNext, ServerStrings.TeamMailboxMessageGoToTheSite + str, ServerStrings.TeamMailboxMessageSendMailToTheSiteMailbox + link); break; case TeamMailboxNotificationType.MemberInvitation: case TeamMailboxNotificationType.Welcome: text = string.Format("<P>{0}</P>", string.Format(ServerStrings.TeamMailboxMessageMemberInvitationBodyIntroText, link, TeamMailboxNotificationHelper.GetLink(this.tm.SharePointUrl, text2))); text += string.Format("<P>{0}</P>", ServerStrings.TeamMailboxMessageToLearnMore + TeamMailboxNotificationHelper.GetLink(TeamMailboxNotificationHelper.HelpLinkLearnMoreWhatAreTeamMailboxes, ServerStrings.TeamMailboxMessageWhatIsSiteMailbox)); break; } return string.Format("<html><body><font face='Segoe UI'>{0}</font></body></html>", text); }
protected virtual Exception ProcessNewOwnersAndMembers(Guid mailboxGuid, List <ADObjectId> newOwners, List <ADObjectId> newMembers) { Exception ex = null; try { this.mailbox = (this.recipientSession.FindByExchangeGuid(mailboxGuid) as ADUser); if (this.mailbox == null) { throw new ObjectNotFoundException(new LocalizedString("Cannot find the team mailbox by mailbox guid " + mailboxGuid)); } this.tm = TeamMailbox.FromDataObject(this.mailbox); } catch (ADTransientException ex2) { ex = ex2; } catch (ADExternalException ex3) { ex = ex3; } catch (ADOperationException ex4) { ex = ex4; } catch (DataValidationException ex5) { ex = ex5; } catch (ObjectNotFoundException ex6) { ex = ex6; } if (ex != null) { ProtocolLog.LogError(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: Failed to find team mailbox {0}", (this.mailbox == null) ? mailboxGuid.ToString() : this.mailbox.PrimarySmtpAddress.ToString()), ex); return(ex); } this.membershipHelper = new TeamMailboxMembershipHelper(this.tm, this.recipientSession); TeamMailboxNotificationHelper teamMailboxNotificationHelper = null; if (this.isFirstSync) { teamMailboxNotificationHelper = new TeamMailboxNotificationHelper(this.tm, this.recipientSession); ADObjectId adobjectId = (this.tm.OwnersAndMembers.Count > 0) ? this.tm.OwnersAndMembers[0] : null; try { if (adobjectId != null) { List <ADObjectId> list = MembershipSynchronizer.ListForSingleId(adobjectId); ProtocolLog.LogStatistics(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: the following users have been added to team mailbox {0}: {1}", this.mailbox.PrimarySmtpAddress, MembershipSynchronizer.GetUsersString(list))); int count = this.tm.Owners.Count; teamMailboxNotificationHelper.SendNotification(list, TeamMailboxNotificationType.MemberInvitation); } } catch (StorageTransientException ex7) { ex = ex7; } catch (StoragePermanentException ex8) { ex = ex8; } if (ex != null) { ProtocolLog.LogError(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: failed sending notifications for team mailbox {0}", this.mailbox.PrimarySmtpAddress), ex); } } new List <ADObjectId>(); IList <ADObjectId> newUserList = TeamMailbox.MergeUsers(newOwners, newMembers); IList <ADObjectId> userList; IList <ADObjectId> list2; bool flag = this.membershipHelper.UpdateTeamMailboxUserList(this.tm.Owners, newOwners, out userList, out list2); IList <ADObjectId> list3; IList <ADObjectId> list4; bool flag2 = this.membershipHelper.UpdateTeamMailboxUserList(this.tm.OwnersAndMembers, newUserList, out list3, out list4); if (flag || flag2) { TeamMailbox.DiffUsers(list3, userList); try { this.membershipHelper.SetTeamMailboxUserPermissions(list3, list4, null, true); } catch (OverflowException ex9) { ex = ex9; } catch (COMException ex10) { ex = ex10; } catch (UnauthorizedAccessException ex11) { ex = ex11; } catch (TransientException ex12) { ex = ex12; } catch (DataSourceOperationException ex13) { ex = ex13; } if (ex != null) { ProtocolLog.LogError(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: failed setting AD permissions for team mailbox {0}", this.mailbox.PrimarySmtpAddress), ex); return(ex); } ProtocolLog.LogStatistics(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: the following users have been added to team mailbox {0}: {1}", this.mailbox.PrimarySmtpAddress, MembershipSynchronizer.GetUsersString(list3))); ProtocolLog.LogStatistics(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: the following users have been removed from team mailbox {0}: {1}", this.mailbox.PrimarySmtpAddress, MembershipSynchronizer.GetUsersString(list4))); try { this.teamMailboxSecurityRefresher.Refresh(this.mailbox, this.recipientSession); } catch (DatabaseNotFoundException ex14) { ex = ex14; } catch (ObjectNotFoundException ex15) { ex = ex15; } if (ex != null) { ProtocolLog.LogError(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: failed setting team mailbox {0} store permissions for userToAdd {1} and usersToRemove {2}", this.mailbox.PrimarySmtpAddress, MembershipSynchronizer.GetUsersString(list3), MembershipSynchronizer.GetUsersString(list4)), ex); } if (teamMailboxNotificationHelper == null) { teamMailboxNotificationHelper = new TeamMailboxNotificationHelper(this.tm, this.recipientSession); } try { teamMailboxNotificationHelper.SendNotification(list3, TeamMailboxNotificationType.MemberInvitation); } catch (StorageTransientException ex16) { ex = ex16; } catch (StoragePermanentException ex17) { ex = ex17; } if (ex != null) { ProtocolLog.LogError(this.loggingComponent, this.loggingContext, string.Format("MembershipSynchronizer.ProcessNewOwnersAndMembers: failed sending member invitation for team mailbox {0}", this.mailbox.PrimarySmtpAddress), ex); } this.usersToUpdateShowInMyClient = new MembershipSynchronizer.UsersToUpdateShowInMyClient(list3, list4, this); while (this.usersToUpdateShowInMyClient.UpdateNextBatch()) { TimeSpan timeSpan; this.IsThrottleDelayNeeded(out timeSpan); } } return(ex); }
public static void SendWelcomeMessageIfNeeded(MailboxSession originalSession) { if (!string.IsNullOrEmpty(originalSession.ClientInfoString) && (originalSession.ClientInfoString.Equals("Client=TeamMailbox;Action=SendWelcomeMessageToSiteMailbox;Interactive=False", StringComparison.OrdinalIgnoreCase) || originalSession.ClientInfoString.Equals("Client=TeamMailbox;Action=GetDiagnostics;Interactive=False", StringComparison.OrdinalIgnoreCase) || originalSession.ClientInfoString.Equals("Client=TeamMailbox;Action=Send_Notification", StringComparison.OrdinalIgnoreCase))) { return; } originalSession.Mailbox.Load(new PropertyDefinition[] { MailboxSchema.SiteMailboxInternalState }); int? siteMailboxInternalState = originalSession.Mailbox.TryGetProperty(InternalSchema.SiteMailboxInternalState) as int?; if (siteMailboxInternalState != null) { if ((siteMailboxInternalState.Value & 1) == 1) { return; } } try { using (MailboxSession mailboxSession = MailboxSession.OpenAsAdmin(originalSession.MailboxOwner, originalSession.InternalCulture, "Client=TeamMailbox;Action=SendWelcomeMessageToSiteMailbox;Interactive=False")) { string internetMessageId = "ed590c4ca1674effa0067475ab2b93b2_" + mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress; using (MessageItem messageItem = MessageItem.CreateForDelivery(mailboxSession, mailboxSession.GetDefaultFolderId(DefaultFolderType.Inbox), internetMessageId, new ExDateTime?(ExDateTime.MinValue))) { messageItem.Recipients.Add(new Participant(mailboxSession.MailboxOwner.MailboxInfo.DisplayName, mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString(), "SMTP")); messageItem.From = new Participant(mailboxSession.MailboxOwner); IRecipientSession recipientSession = null; TeamMailbox teamMailbox = TeamMailboxNotificationHelper.GetTeamMailbox(mailboxSession, out recipientSession); TeamMailboxNotificationHelper teamMailboxNotificationHelper = new TeamMailboxNotificationHelper(teamMailbox, recipientSession); messageItem.Subject = teamMailboxNotificationHelper.GetSubject(TeamMailboxNotificationType.Welcome); using (Stream stream = messageItem.Body.OpenWriteStream(new BodyWriteConfiguration(BodyFormat.TextHtml, Charset.Unicode))) { using (StreamWriter streamWriter = new StreamWriter(stream, Encoding.Unicode)) { streamWriter.WriteLine(teamMailboxNotificationHelper.GetBody(TeamMailboxNotificationType.Welcome)); } } messageItem.AutoResponseSuppress = AutoResponseSuppress.All; messageItem.InternetMessageId = internetMessageId; messageItem.PropertyBag[InternalSchema.SentTime] = ExDateTime.UtcNow; mailboxSession.Deliver(messageItem, ProxyAddress.Parse(ProxyAddressPrefix.Smtp.PrimaryPrefix, mailboxSession.MailboxOwner.MailboxInfo.PrimarySmtpAddress.ToString()), RecipientItemType.To); } TeamMailboxNotificationHelper.UpdateWelcomeMessageSentState(siteMailboxInternalState, mailboxSession); } } catch (StoragePermanentException ex) { if (ex.InnerException != null && ex.InnerException is MapiExceptionDuplicateDelivery) { using (MailboxSession mailboxSession2 = MailboxSession.OpenAsAdmin(originalSession.MailboxOwner, originalSession.Culture, "Client=TeamMailbox;Action=SendWelcomeMessageToSiteMailbox;Interactive=False")) { TeamMailboxNotificationHelper.UpdateWelcomeMessageSentState(siteMailboxInternalState, mailboxSession2); goto IL_27D; } goto IL_27B; IL_27D: return; } IL_27B: throw; } }
private static string GetLink(Uri link, string str) { string link2 = (link == null) ? string.Empty : link.AbsoluteUri; return TeamMailboxNotificationHelper.GetLink(link2, str); }