exchange online with sharepoint - improve your app

60
Comunidade Portuguesa de SharePoint 15ª Reunião Presencial 10/12/2011

Upload: joao-livio

Post on 22-Nov-2014

1.457 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Exchange Online with SharePoint - Improve Your App

Comunidade Portuguesa de SharePoint

15ª Reunião Presencial

10/12/2011

Page 2: Exchange Online with SharePoint - Improve Your App

Exchange Online with SharePointImprove your App!

SharePoint work is something you do that nobody notices until you don't do it

Source: http://www.paulswider.com

Page 3: Exchange Online with SharePoint - Improve Your App

JOÃO TITO LÍVIO

SharePoint Programmer

MCTS - SharePoint 2010 Application DevelopmentMicrosoft MVP Office Systems:Development (2002-present)

C#, VB.NET, VSTOWindows Forms DevelopmentWebForms DevelopmentSharePoint DevelopmentSharePoint Administration Celebrating 10 Years as MVP

Page 4: Exchange Online with SharePoint - Improve Your App

Sumário• Exchange Web Services API, o que é?

– Introdução– Vantagens– Desvantagens– Evolução– Classes

• EWS – Ligação ao Exchange Online– Item – Trabalhar com Mensagens– Folder – Trabalhar com Folders Exchange– Attachments – Trabalhar com Anexos

• Integração com o SharePoint 2010 e SharePoint Online• Remote PowerShell e Microsoft Online Service Module para PowerShell• Office 365 UI para gestão de Licenças e Contas Exchange

Page 5: Exchange Online with SharePoint - Improve Your App

Exchange Web Services Managed API

Page 6: Exchange Online with SharePoint - Improve Your App

Introdução – EWS o que é?

DLL fornecido pela Microsoft (Abstraction Layer)http://www.microsoft.com/download/en/details.aspx?id=13480

Comunicação Bidireccional com ExchangeUsa mensagens EWS SOAP para comunicarCamada Developer Friendly que utiliza um ASMX

A Microsoft encoraja os Developers a Utiliza-la

Para gestão de domínio e gestão de contas tem de se utilizar obrigatoriamente PowerShell pois fica de fora da API

Existe um PowerShell Toolkit disponível para Downloadhttp://archive.msdn.microsoft.com/psoutlooklive/Release/ProjectReleases.aspx?ReleaseId=4513

Page 7: Exchange Online with SharePoint - Improve Your App

Vantagens

What you see is what you get (Ready Made)Basta instanciar as classes do DLLMenos linhas de CódigoEm SharePoint facilita muito o Deploy

A ter em atenção, mas SharePoint = ~ Máquinas Dedicadas, temos controlo do que está instalado

To help prevent conflicts between different versions of the EWS Managed API installed by other applications, do not install the EWS Managed API assembly in the Global Assembly Cache (GAC).

Page 8: Exchange Online with SharePoint - Improve Your App

Desvantagens

Estamos limitados ao que a Microsoft Expõem no DLL

Persistência de ObjetosNão é serializável porque não tem construtor padrão.

Page 9: Exchange Online with SharePoint - Improve Your App

Evolução05-06-2010Microsoft Exchange Web Services (EWS) Managed API 1.1 BetaTarget Exchange 2010 SP1Supported Operating Systems: Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows VistaNOTE: Requires Microsoft .NET Framework 3.5 and Microsoft Visual Studio 2008 or later

15-11-2010Microsoft Exchange Web Services (EWS) Managed API 1.1Target Exchange 2010 SP1Supported Operating Systems: Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows VistaNOTE: Requires Microsoft .NET Framework 3.5 and Microsoft Visual Studio 2008 or later

DateTime.Parse(?) Microsoft Exchange Web Services (EWS) Managed API 1.2Target Exchange 2010 SP2Supported Operating Systems: Windows 7, Windows Server 2008, Windows Server 2008 R2, Windows VistaNOTE: Requires Microsoft .NET Framework 3.5 and Microsoft Visual Studio 2008 or laterhttp://msdn.microsoft.com/en-us/library/dd633710(v=exchg.80).aspxDownload? Ainda não está disponível

Page 10: Exchange Online with SharePoint - Improve Your App

Classes – Folder

Page 11: Exchange Online with SharePoint - Improve Your App

Classes – Item

Itens e pastas no Exchange são identificados exclusivamente. No EWS Managed API, itens e pastas têm uma propriedade ID que mantém a sua identidade única. O ID de um item é do tipo ItemId, o ID de uma pasta é do tipo FolderId.

Page 12: Exchange Online with SharePoint - Improve Your App

Comunicar com o Exchange On Premises (na vossa empresa) Na Cloud

Page 13: Exchange Online with SharePoint - Improve Your App

EWS – Autodisovery Service

Page 14: Exchange Online with SharePoint - Improve Your App

EWS Autodiscovery Service

0 – Resolve Utilizador1 – Vai à procura do Web Service2 – Encontra o Servidor4 – Estabelece Ligação5 – Transporta Definições6 – Configura Outlook

Page 15: Exchange Online with SharePoint - Improve Your App

EWS Autodiscovery Service TRACE

• Trace ? (Find or discover) Temos de Ativar?• Trace para a CLOUD– Credenciais (Caixa Correio e Password)

• Ativar o Trace TraceEnable = true (ou não)

– Prevenir que não vamos à nossa AD• Definir a propriedade EnableScpLookup = false (ou não)

– Obter o Endpoint (Exchange Service) para a Caixa Correio• Indica-nos o Servidor onde está alojada a Caixa de Correio• https://SERVER.outlook.com/EWS/Exchange.asmx

– BIND do Exchange Service Object

dominio.pt > outlook.com > server.outlook.com

Page 16: Exchange Online with SharePoint - Improve Your App

EWS Autodiscovery Service TRACE<Trace Tag="AutodiscoverConfiguration" Tid="10" Time="2011-08-02 16:30:13Z">Host returned enabled endpoint flags: Legacy</Trace><Trace Tag="AutodiscoverConfiguration" Tid="10" Time="2011-08-02 16:30:13Z">Trying to get Autodiscover redirection URL from

http://autodiscover.DOMINIO.PT/autodiscover/autodiscover.xml.</Trace><Trace Tag="AutodiscoverConfiguration" Tid="10" Time="2011-08-02 16:30:13Z">

Redirection URL found: 'https://autodiscover-s.OUTLOOK.COM/autodiscover/autodiscover.xml'</Trace><Trace Tag="AutodiscoverConfiguration" Tid="10" Time="2011-08-02 16:30:13Z">Determining which endpoints are enabled for host autodiscover-s.outlook.com</Trace><Trace Tag="AutodiscoverRequestHttpHeaders" Tid="10" Time="2011-08-02 16:30:14Z">POST /autodiscover/autodiscover.svc HTTP/1.1Content-Type: text/xml; charset=utf-8Accept: text/xmlUser-Agent: ExchangeServicesClient/14.02.0051.000</Trace><Trace Tag="AutodiscoverRequest" Tid="10" Time="2011-08-02 16:30:14Z" Version="14.02.0051.000"> <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:a="http://schemas.microsoft.com/exchange/2010/Autodiscover" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header> <a:RequestedServerVersion>Exchange2010</a:RequestedServerVersion>

<wsa:Action>http://schemas.microsoft.com/exchange/2010/Autodiscover/Autodiscover/GetUserSettings</wsa:Action>

Page 17: Exchange Online with SharePoint - Improve Your App

EWS Autodiscovery em SharePoint

• Trace para a CLOUD– Credenciais (Caixa Correio e Password)

• Ativar o Trace TraceEnable = true

• Prevenir que não vamos à nossa AD (ou não)• Definir a propriedade EnableScpLookup = false (ou não)

– Passar diretamente o URL do Serviço• https://SERVER.outlook.com/EWS/Exchange.asmx

– Passar um Certificado X509 como Dummy• ServicePointManager.ServerCertificateValidationCallback += RemoteCertificateValidationHandler

– BIND do Exchange Service Object

Page 18: Exchange Online with SharePoint - Improve Your App

EWS – Boas Práticas

Page 19: Exchange Online with SharePoint - Improve Your App

Best Practices

• Usar Impersonation em vez de passar novas Cred’s• Tentar realizar o menor número de Bindig’s• Ler Documentação

EWS Managed API Referencehttp://msdn.microsoft.com/en-us/library/gg248112(v=EXCHG.80).aspx

Page 20: Exchange Online with SharePoint - Improve Your App

User Impersonation

Page 21: Exchange Online with SharePoint - Improve Your App

Activar User Impersonation

Enable Impersonation: http://msdn.microsoft.com/en-us/library/bb204095(EXCHG.140).aspx

Page 22: Exchange Online with SharePoint - Improve Your App

User Impersonation

• Porquê?– Non Admin - não tem controlo total sobre o Web Service– Garantimos que executamos todas as operações

service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, _user);

Page 23: Exchange Online with SharePoint - Improve Your App

DEMO

Page 24: Exchange Online with SharePoint - Improve Your App

Gestão de Mensagens

Page 25: Exchange Online with SharePoint - Improve Your App

Gestão de Mensagens• Folders de Exchange– WellKnownFolderName (ENUM)

• ArchiveDeletedItems• ArchiveMsgFolderRoot• ArchiveRecoverableItemsDeletions• ArchiveRecoverableItemsPurges• ArchiveRecoverableItemsRoot• ArchiveRecoverableItemsVersions• ArchiveRoot• Calendar• Contacts• DeletedItems• Drafts• Inbox• Journal• JunkEmail• MsgFolderRoot• Notes• Outbox• PublicFoldersRoot• RecoverableItemsDeletions• RecoverableItemsPurges

Page 26: Exchange Online with SharePoint - Improve Your App

Query Básico a Folders

Page 27: Exchange Online with SharePoint - Improve Your App

DEMO

Page 28: Exchange Online with SharePoint - Improve Your App

Gestão de Mensagens

• Obter Mensagens na Inbox– ItemView– SearchFilter– FindItemsResults<Item> (WellKnownFolderName.Inbox)– foreach (Item item in findResults.Items)– Item mess = Item.Bind(GetBinding(), item.Id.UniqueId);

• UniqueId• ReceivedDate …

– EmailMessage message = mess as EmailMessage;• Subject• From• From.Address …

Page 29: Exchange Online with SharePoint - Improve Your App

DEMO

Page 30: Exchange Online with SharePoint - Improve Your App

Gestão de Mensagens

• Renderizar HTML de uma Mensagem– Necessitamos de saber o seu UniqueID– Fazer o request do Body

• Plain Text• HTML

– Verificar se tem Attachments e InLine Attachments• Tipo “cid:”• Fazer o Load do Content para a Memória• Converter o Content para Base 64 - incluir no HTML

– “Despejar” o HTML tratado por exemplo num LITERAL

Não utilizar ID como QueryString pois ID é reservado no SharePoint 2010

Page 31: Exchange Online with SharePoint - Improve Your App

DEMO

Page 32: Exchange Online with SharePoint - Improve Your App

Gestão de Mensagens

• Enviar Mensagem através da API– ExchangeService service,– string subject– string body

• Tipo que queremos Plain Text ou HTML

– IEnumerable<string> mailTo,– IEnumerable<string> mailCc,– IEnumerable<string> mailBcc,– IEnumerable<string> attachments– message.Send (); – message.SendAndSaveCopy(); (FolderID, WellKnownFolderName)

Page 33: Exchange Online with SharePoint - Improve Your App

DEMO

Page 34: Exchange Online with SharePoint - Improve Your App

Gestão de Mensagens

• Responder e Encaminhar Mensagens– message.Reply(messageBody, bool replyAll);– messageForward(messageBody, param[] ToRecipients);– messageForward(messageBody, IEnumerable ToRecipients);

– message.CreateReply();– message.CreateForward();

var message = (EmailMessage) Item.Bind(service, new ItemId(uniqueId), PropertySet.FirstClassProperties);var reply = message.CreateReply(false);reply.BodyPrefix = "Body vai aqui";var replyMessage = reply.Save(WellKnownFolderName.Drafts);replyMessage.ToRecipients.Add("[email protected]");replyMessage.CcRecipients.Add("[email protected]");replyMessage.Attachments.AddFileAttachment("d:\\inbox\\teste.pdf");replyMessage.Update(ConflictResolutionMode.AlwaysOverwrite);replyMessage.SendAndSaveCopy();

Page 35: Exchange Online with SharePoint - Improve Your App

Gestão de Mensagens

• REPLY e FORWARD– O EWS encarrega-se de formatar a mensagem

Page 36: Exchange Online with SharePoint - Improve Your App

DEMO

Page 37: Exchange Online with SharePoint - Improve Your App

Gestão de Pastas

Page 38: Exchange Online with SharePoint - Improve Your App

Gestão de Pastas

• Cada Pasta tem um UniqueID diferente

– FolderView view– SearchFilter searchFilter– FindFoldersResults findFolderResults– foreach (Folder myFolder in findFolderResults.Folders)– if (findFolderResults.MoreAvailable)• moffset = moffset + pageSize;• EnumeraPastasRoot(service, moffset);

Page 39: Exchange Online with SharePoint - Improve Your App

DEMO

Page 40: Exchange Online with SharePoint - Improve Your App

Gestão de Anexos

Page 41: Exchange Online with SharePoint - Improve Your App

Gestão de Anexos

• ExchangeService service• EmailMessage message = EmailMessage.Bind• foreach (Attachment att in message.Attachments)

Page 42: Exchange Online with SharePoint - Improve Your App

DEMO

Page 43: Exchange Online with SharePoint - Improve Your App

Mailbox vs Shared Mailbox

• Mailbox requer uma Licença Office 365• Shared Mailbox não requer uma Licença Office

365, mas cada utilizador que acede à mesma necessita de uma Licença.

Page 44: Exchange Online with SharePoint - Improve Your App

SharePoint Online

Page 45: Exchange Online with SharePoint - Improve Your App

SharePoint Online

• Sandbox Solution– Como sabem o DLL não entra no Office 365– Workaround’s• Criar uma camada de Web Services • MS Exchange Server 2010 SP2 Web Services SDK

http://www.microsoft.com/download/en/details.aspx?id=13082

Developing for SharePoint Online with Sandbox Solutionshttp://msdn.microsoft.com/en-us/Office365TrainingCourse_2V_1

SharePoint Online for Office 365 Developer Guidehttp://msdn.microsoft.com/en-us/library/hh147180.aspx

Page 46: Exchange Online with SharePoint - Improve Your App

Remote PowerShellMicrosoft Online Service Module

Page 47: Exchange Online with SharePoint - Improve Your App

Requisitos para Administração

Page 48: Exchange Online with SharePoint - Improve Your App

CmdLets Enterprise

• Instalar Windows PowerShell 2.0 e AD FS 2.0• Configurar as Desktop Apps (sign up assistant 7.0)

• Instalar Microsoft Online Services Module

Windows PowerShell 2.0 e AD FS 2.0http://social.technet.microsoft.com/wiki/contents/articles/2735.aspx

Desktop Apps (sign up assistant 7.0)DEMO

Microsoft Online Services Modulehttp://onlinehelp.microsoft.com/en-us/office365-enterprises/ff652560.aspx

Page 49: Exchange Online with SharePoint - Improve Your App

Administração Office 365Granular license assignment from PowerShellhttp://community.office365.com/en-us/w/officeapps/granular-license-assignment-from-powershell.aspx

Install and configure the Microsoft Online Services Module for Windows PowerShell for single sign-onhttp://onlinehelp.microsoft.com/en-us/office365-enterprises/ff652560.aspx

Page 50: Exchange Online with SharePoint - Improve Your App

PowerShell Toolkit para Live@Eduhttp://archive.msdn.microsoft.com/psoutlooklive/Release/ProjectReleases.aspx?ReleaseId=4513

Page 51: Exchange Online with SharePoint - Improve Your App

Instalar e configurar o PowerShell

1. Desinstalar versões anteriores do Windows PowerShell do seu computador

2. Desinstalar versões anteriores do WinRM do seu computador

3. Instalar o Windows Management Framework4. Verificar se o Windows PowerShell pode executar

scripts5. Verificar se o WinRM (Windows Remote Management)

permite que o Windows PowerShell se conecte

Page 52: Exchange Online with SharePoint - Improve Your App

Instalar e configurar o PowerShell

• Verificar se o Windows PowerShell pode executar scripts

Page 53: Exchange Online with SharePoint - Improve Your App

Instalar e configurar o PowerShell

• Verificar se o WinRM permite que o Windows PowerShell se conecte

Page 54: Exchange Online with SharePoint - Improve Your App

Conetar ao Windows PowerShellMáximo de 3 conexões simultâneas

$LiveCred = Get-Credential $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri "https://pod51011psh.outlook.com/PowerShell-LiveID?PSVersion=2.0" -Credential $LiveCred -Authentication Basic -AllowRedirection $Office365PS = Import-PSSession $Session

Page 55: Exchange Online with SharePoint - Improve Your App

DEMO

Page 56: Exchange Online with SharePoint - Improve Your App

Exchange Online UI

Page 57: Exchange Online with SharePoint - Improve Your App

DEMO

Page 59: Exchange Online with SharePoint - Improve Your App

Questões? Sugestões? Sessões futuras apenas de Gestão PowerShell?

Page 60: Exchange Online with SharePoint - Improve Your App

Obrigado! [email protected] http://pt.linkedin.com/in/jliviohttp://www.facebook.com/jliviohttp://twitter.com/jliviohttp://www.slideshare.net/jlivio1

Meu Online Services Blog: http://exchws.wordpress.com/