Zugriff auf Microsoft365 E-Mail Postfach

<Batch ActionLog="true" ConditionLog="false">

	<Set Variable="{@UserPrincipalName}" Value="[email protected]" />
	<Set Variable="{@QuellFolderID}" Value="inbox" />
	<Set Variable="{@ZielFolderID}" Value="inbox" />
	
	<SQLConnect Connection="{@myConnection}" Server="{@SQLServer}" Database="{@SQLDatabase}" User="{@SQLUsername}" Password="{@SQLPassword}" />


	<!-- Email Ordner IDs auslesen -->
	<Microsoft365MailFolderList Data="{@myFolder}" UserPrincipalName="{@UserPrincipalName}" Account="{@Account:Office}" />
	
	<ForEach Data="{@myFolder}">
	
		<Select Case="{@Data:displayName}">
	        <Case Value="Quelle">
				<Set Variable="{@QuellFolderID}" Value="{@Data:id}" />
	        </Case>
	        <Case Value="Ziel">
				<Set Variable="{@ZielFolderID}" Value="{@Data:id}" />
	        </Case>
        </Select>	

    </ForEach>

	<!-- Emails aus Quell-Ordner einlesen -->
	<Microsoft365MailList Data="{@myEmails}" FolderId="{@QuellFolderID}" UserPrincipalName="{@UserPrincipalName}" Account="{@Account:Office}" />

	<!-- Emails per DataTable filtern -->
	<DataCopy Data="{@myEmails}" DataCopy="{@myEmailsFiltered}" Where="toRecipients Like('%[email protected]%')" />


	<!-- Details der Email auslesen und verarbeiten -->
	<ForEach Data="{@myEmailsFiltered}">

		<Set Variable="{@Subject}" Value="{@Data:subject}" />
		
		<!-- Emailtext auslesen -->
		<Microsoft365MailRead MailId="{@Data:id}" HtmlBody="true" UserPrincipalName="{@UserPrincipalName}" Account="{@Account:Office}" Variable="{@HtmlBody}" />

		<!-- Emailtext in Datenbank speichern -->
		<SQLExecute Query="INSERT INTO ..." Connection="{@myConnection}" Variable="{@Result}" />
		
		<!-- Attachments der Email runterladen -->
		<CreateNewGuid Variable="{@Guid}" />
		<Set Variable="{@Path}" Value="C:\temp\{@Guid}\" />
		<PathCreate Path="{@Path}" Variable="{@Result}" />
		
		<Microsoft365MailAttachmentDownloadAll MailId="{@Data:id}" DestinationFolder="{@Path}" UserPrincipalName="{@UserPrincipalName}" Account="{@Account:Office}" />

		<!-- Email in .eml Datei exportieren -->
		<Microsoft365MailExportToEml MailId="{@Data:id}" DestinationFolder="{@Path}" FileName="export.eml" UserPrincipalName="{@UserPrincipalName}" Account="{@Account:Office}" Variable="{@Result}" />

		<!-- Email in Ziel-Ordner verschieben -->
		<Microsoft365MailMove MailId="{@Data:id}" DestinationFolderId="{@ZielFolderID}" UserPrincipalName="{@UserPrincipalName}" Account="{@Account:Office}" />

    </ForEach>

</Batch>