Exemplo n.º 1
0
        private DeletionResult DeleteMessageFromOutboxHelper(DeleteMapiMailDefinition deleteMapiMailDefinition)
        {
            DeletionResult    result = DeletionResult.Fail;
            string            domainPartOfEmailAddress = MapiMessageSubmitter.GetDomainPartOfEmailAddress(deleteMapiMailDefinition.SenderEmailAddress);
            ExchangePrincipal mailboxOwner             = ExchangePrincipal.FromProxyAddress(ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(domainPartOfEmailAddress), deleteMapiMailDefinition.SenderEmailAddress);
            QueryFilter       queryFilter = new AndFilter(new List <QueryFilter>(2)
            {
                new TextFilter(ItemSchema.InternetMessageId, deleteMapiMailDefinition.InternetMessageId, MatchOptions.FullString, MatchFlags.IgnoreCase),
                new TextFilter(StoreObjectSchema.ItemClass, deleteMapiMailDefinition.MessageClass, MatchOptions.FullString, MatchFlags.IgnoreCase)
            }.ToArray());

            using (MailboxSession mailboxSession = MailboxSession.OpenAsTransport(mailboxOwner, "Client=Monitoring;Action=MapiSubmitLAMProbe"))
            {
                using (Folder folder = Folder.Bind(mailboxSession, DefaultFolderType.Outbox))
                {
                    using (QueryResult queryResult = folder.ItemQuery(ItemQueryType.None, queryFilter, null, new PropertyDefinition[]
                    {
                        ItemSchema.Id
                    }))
                    {
                        object[][] rows = queryResult.GetRows(1);
                        if (rows == null || rows.Length == 0)
                        {
                            result = DeletionResult.NoMatchingMessage;
                        }
                        else
                        {
                            mailboxSession.Delete(DeleteItemFlags.HardDelete, new StoreId[]
                            {
                                ((VersionedId)rows[0][0]).ObjectId
                            });
                            result = DeletionResult.Success;
                        }
                    }
                }
            }
            return(result);
        }
 public override IMapiMessageSubmitter MakeMapiMessageSubmitter()
 {
     return(MapiMessageSubmitter.CreateInstance());
 }
Exemplo n.º 3
0
        private void SendMapiMessageHelper(bool setLamNotificationId, string lamNotificationId, SendMapiMailDefinition mapiMailDefinition, bool returnOutParameters, out string entryId, out string internetMessageId, out Guid senderMbxGuid)
        {
            entryId           = string.Empty;
            internetMessageId = string.Empty;
            senderMbxGuid     = Guid.Empty;
            ExchangePrincipal mailboxOwner;

            if (mapiMailDefinition.SenderMbxGuid != Guid.Empty)
            {
                mailboxOwner = ExchangePrincipal.FromMailboxData(mapiMailDefinition.SenderMbxGuid, mapiMailDefinition.SenderMdbGuid, new List <CultureInfo>(0));
            }
            else
            {
                string domainPartOfEmailAddress = MapiMessageSubmitter.GetDomainPartOfEmailAddress(mapiMailDefinition.SenderEmailAddress);
                mailboxOwner = ExchangePrincipal.FromProxyAddress(ADSessionSettings.RootOrgOrSingleTenantFromAcceptedDomainAutoDetect(domainPartOfEmailAddress), mapiMailDefinition.SenderEmailAddress);
            }
            using (MailboxSession mailboxSession = MailboxSession.OpenAsTransport(mailboxOwner, "Client=Monitoring;Action=MapiSubmitLAMProbe"))
            {
                using (MessageItem messageItem = MessageItem.Create(mailboxSession, mailboxSession.GetDefaultFolderId(DefaultFolderType.Outbox)))
                {
                    messageItem.ClassName = mapiMailDefinition.MessageClass;
                    if (setLamNotificationId)
                    {
                        messageItem[MessageItemSchema.MapiSubmitLamNotificationId] = lamNotificationId;
                        messageItem[MessageItemSchema.XLAMNotificationId]          = lamNotificationId;
                    }
                    messageItem[MessageItemSchema.DoNotDeliver] = (mapiMailDefinition.DoNotDeliver ? "Supress" : "Deliver");
                    if (mapiMailDefinition.DropMessageInHub)
                    {
                        messageItem[MessageItemSchema.DropMessageInHub] = "FrontEnd-CAT-250";
                        messageItem[MessageItemSchema.SystemProbeDrop]  = "OnEndOfHeaders";
                    }
                    messageItem.Subject = mapiMailDefinition.MessageSubject;
                    BodyWriteConfiguration configuration = new BodyWriteConfiguration(BodyFormat.TextPlain);
                    using (TextWriter textWriter = messageItem.Body.OpenTextWriter(configuration))
                    {
                        textWriter.Write(mapiMailDefinition.MessageBody);
                    }
                    messageItem.Recipients.Add(new Participant(mapiMailDefinition.RecipientEmailAddress, mapiMailDefinition.RecipientEmailAddress, "SMTP"), RecipientItemType.To);
                    if (mapiMailDefinition.DeleteAfterSubmit)
                    {
                        messageItem.SendWithoutSavingMessage();
                    }
                    else
                    {
                        messageItem.Send();
                    }
                    if (returnOutParameters)
                    {
                        senderMbxGuid = mailboxSession.MailboxGuid;
                        messageItem.Load(new PropertyDefinition[]
                        {
                            StoreObjectSchema.EntryId,
                            ItemSchema.InternetMessageId
                        });
                        object obj      = messageItem.TryGetProperty(StoreObjectSchema.EntryId);
                        byte[] entryId2 = (byte[])obj;
                        entryId = MapiMessageSubmitter.EntryIdString(entryId2);
                        object obj2 = messageItem.TryGetProperty(ItemSchema.InternetMessageId);
                        internetMessageId = obj2.ToString();
                    }
                }
            }
        }