/// <summary>
        /// This function call other function according to the argument supplied.
        /// This is main function for this class
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(CodeActivityContext context)
        {
            // ***************  getting the input values ************************
            string          folderName      = FolderName.Get(context);
            string          mailBoxName     = MailBoxName.Get(context);
            ExchangeService service         = ObjExchangeService.Get(context);
            Int32           numOfMails      = numberOfMails.Get(context);
            string          mailSubject     = Subject.Get(context);
            bool            IsExact         = MatchExactSubject.Get(context);
            bool            onlyUnreadMails = ReadOnlyUnread.Get(context);

            if (mailSubject is null)
            {
                EmailMessages.Set(context, ReadMailFromFolder(service, folderName, numOfMails, mailBoxName, onlyUnreadMails));
            }
            else
            {
                EmailMessages.Set(context, ReadMailFromFolderSubjectFilter(service, folderName, numOfMails, mailBoxName, mailSubject, IsExact));
            }
        }
        /// <summary>
        /// Shared mail logic for downloading attachments
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(CodeActivityContext context)
        {
            // ****************** getting the input values ************************
            ExchangeService objExchangeService = ObjExchangeService.Get(context);
            Item            mail       = Mail.Get(context);
            string          folderPath = FolderPath.Get(context);


            //******** Downloading the all attachment from mail ******
            EmailMessage email = EmailMessage.Bind(objExchangeService, mail.Id, new PropertySet(ItemSchema.Attachments));

            foreach (Attachment attachment in email.Attachments)
            {
                if (attachment is FileAttachment)
                {
                    FileAttachment fileAttachment = attachment as FileAttachment;
                    // Load the attachment into a folder.
                    fileAttachment.Load(folderPath + "\\" + fileAttachment.Name);
                }
            }
        }
示例#3
0
        /// <summary>
        /// Logic for moving mails
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(CodeActivityContext context)
        {
            // ****************** getting the input values ************************
            ExchangeService objExchangeService = ObjExchangeService.Get(context);
            Item            mail        = Mail.Get(context);
            string          mailboxName = MailboxName.Get(context);
            string          folderName  = FolderName.Get(context);

            //********** Logic to move a mail from a folder to another ************
            FolderView view = new FolderView(10000);

            view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
            view.PropertySet.Add(FolderSchema.DisplayName);
            view.Traversal = FolderTraversal.Deep;
            Mailbox            mailbox           = new Mailbox(mailboxName);
            FindFoldersResults findFolderResults = objExchangeService.FindFolders(new FolderId(WellKnownFolderName.MsgFolderRoot, mailbox), view);
            bool flag = false;

            foreach (Folder folder in findFolderResults)
            {
                //Searching for supplied folder into mailbox
                if (folder.DisplayName.Equals(folderName))
                {
                    PropertySet propSet = new PropertySet(BasePropertySet.IdOnly, EmailMessageSchema.Subject, EmailMessageSchema.ParentFolderId);
                    // Bind to the existing item by using the ItemId.
                    EmailMessage beforeMessage = EmailMessage.Bind(objExchangeService, mail.Id, propSet);
                    // Move the specified mail to the given folder
                    beforeMessage.Move(folder.Id);
                    flag = true;
                    break;
                }
            }
            if (!flag)
            {
                throw new Exception("Supplied folder is not found");
            }
        }
示例#4
0
        /// <summary>
        /// Shared Mail logic for replying to a mail
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(CodeActivityContext context)
        {
            // ****************** getting the input values ************************
            ExchangeService objExchangeService = ObjExchangeService.Get(context);
            Item            mail           = Mail.Get(context);
            string          body           = Body.Get(context);
            bool            isBodyHTML     = IsBodyHTML.Get(context);
            string          recipientEmail = RecipientEmail.Get(context);
            string          cc             = Cc.Get(context);
            string          bcc            = Bcc.Get(context);
            string          sender         = Sender.Get(context);

            //******** Sending mail Logic ******
            EmailMessage    email          = EmailMessage.Bind(objExchangeService, mail.Id, new PropertySet(ItemSchema.Attachments));
            ResponseMessage forwardMessage = email.CreateForward();

            //Check for if body is a HTML content
            if (isBodyHTML)
            {
                forwardMessage.BodyPrefix = new MessageBody(BodyType.HTML, body);
            }
            else
            {
                forwardMessage.BodyPrefix = body;
            }

            //Adding recipients to mail
            string[] emails = recipientEmail.Split(';');
            foreach (string recipient in emails)
            {
                forwardMessage.ToRecipients.Add(recipient);
            }

            //Adding Cc to mail
            if (cc != null && cc.Length > 0)
            {
                string[] emailsCc = cc.Split(';');
                foreach (string recipient in emailsCc)
                {
                    forwardMessage.CcRecipients.Add(recipient);
                }
            }

            //Adding Bcc to mail
            if (bcc != null && bcc.Length > 0)
            {
                string[] emailsBcc = bcc.Split(';');
                foreach (string recipient in emailsBcc)
                {
                    forwardMessage.BccRecipients.Add(recipient);
                }
            }


            //Forwarding mail
            {
                FolderView view = new FolderView(10000);
                view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
                view.PropertySet.Add(FolderSchema.DisplayName);
                view.Traversal = FolderTraversal.Deep;
                Mailbox            mailbox           = new Mailbox(sender);
                FindFoldersResults findFolderResults = objExchangeService.FindFolders(new FolderId(WellKnownFolderName.MsgFolderRoot, mailbox), view);

                foreach (Folder folder in findFolderResults)
                {
                    if (folder.DisplayName == "Sent Items")
                    {
                        forwardMessage.SendAndSaveCopy(folder.Id);
                    }
                }
            }
        }
        /// <summary>
        ///   This function for this class
        ///   It will send mails
        ///   Having option to have attachment
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(CodeActivityContext context)
        {
            // getting the input values ************************
            ExchangeService objExchangeService = ObjExchangeService.Get(context);
            string          subject            = Subject.Get(context);
            string          body           = Body.Get(context);
            string          sender         = Sender.Get(context);
            bool            isBodyHTML     = IsBodyHTML.Get(context);
            string          recipientEmail = RecipientEmail.Get(context);
            string          cc             = Cc.Get(context);
            string          bcc            = Bcc.Get(context);

            string[] attachments = Attachments.Get(context);

            //***** Sending mail Logic ******
            EmailMessage email = new EmailMessage(objExchangeService);

            //Check for if body is a HTML content
            if (isBodyHTML)
            {
                email.Body = new MessageBody(BodyType.HTML, body);
            }
            else
            {
                email.Body = body;
            }

            // Adding Subject to mail
            email.Subject = subject;

            //Adding recipients to mail
            string[] recipients = recipientEmail.Split(';');
            foreach (string recipient in recipients)
            {
                email.ToRecipients.Add(recipient);
            }

            //If attachments
            if (attachments != null && attachments.Length > 0)
            {
                foreach (string attachment in attachments)
                {
                    email.Attachments.AddFileAttachment(attachment);
                }
            }

            //If CC is available
            if (cc != null && cc.Length > 0)
            {
                //Adding recipients to mail
                string[] recipientsCC = cc.Split(';');
                foreach (string recipient in recipientsCC)
                {
                    email.CcRecipients.Add(recipient);
                }
            }

            //If BCC is available
            if (bcc != null && bcc.Length > 0)
            {
                //Adding recipients to mail
                string[] recipientsBcc = bcc.Split(';');
                foreach (string recipient in recipientsBcc)
                {
                    email.BccRecipients.Add(recipient);
                }
            }

            //Sending mail and saving it into sent folder
            email.From = sender;


            FolderView view = new FolderView(10000);

            view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
            view.PropertySet.Add(FolderSchema.DisplayName);
            view.Traversal = FolderTraversal.Deep;
            Mailbox            mailbox           = new Mailbox(sender);
            FindFoldersResults findFolderResults = objExchangeService.FindFolders(new FolderId(WellKnownFolderName.MsgFolderRoot, mailbox), view);

            foreach (Folder folder in findFolderResults)
            {
                if (folder.DisplayName == "Sent Items")
                {
                    email.SendAndSaveCopy(folder.Id);
                }
            }
        }
示例#6
0
        /// <summary>
        /// Shared Mail logic for replying to a mail
        /// </summary>
        /// <param name="context"></param>
        protected override void Execute(CodeActivityContext context)
        {
            // ****************** getting the input values ************************
            ExchangeService objExchangeService = ObjExchangeService.Get(context);
            Item            mail       = Mail.Get(context);
            string          body       = Body.Get(context);
            bool            isBodyHTML = IsBodyHTML.Get(context);
            //string recipientEmail = RecipientEmail.Get(context);
            string cc     = Cc.Get(context);
            string bcc    = Bcc.Get(context);
            string sender = Sender.Get(context);

            string[] attachments = Attachments.Get(context);
            bool     isReplyAll  = ReplyAll.Get(context);

            //******** Sending mail Logic ******
            EmailMessage    email           = EmailMessage.Bind(objExchangeService, mail.Id, new PropertySet(ItemSchema.Attachments));
            ResponseMessage responseMessage = email.CreateReply(isReplyAll);

            //Check for if body is a HTML content
            if (isBodyHTML)
            {
                responseMessage.BodyPrefix = new MessageBody(BodyType.HTML, body);
            }
            else
            {
                responseMessage.BodyPrefix = body;
            }

            //If CC is available
            if (cc != null && cc.Length > 0)
            {
                //Adding recipients to mail
                string[] recipientsCC = cc.Split(';');
                foreach (string recipient in recipientsCC)
                {
                    responseMessage.CcRecipients.Add(recipient);
                }
            }

            //If BCC is available
            if (bcc != null && bcc.Length > 0)
            {
                //Adding recipients to mail
                string[] recipientsBcc = bcc.Split(';');
                foreach (string recipient in recipientsBcc)
                {
                    responseMessage.BccRecipients.Add(recipient);
                }
            }


            //Check if attachment is available
            //If attachments
            if (attachments != null && attachments.Length > 0)
            {
                FolderView view = new FolderView(10000);
                view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
                view.PropertySet.Add(FolderSchema.DisplayName);
                view.Traversal = FolderTraversal.Deep;
                Mailbox            mailbox           = new Mailbox(sender);
                FindFoldersResults findFolderResults = objExchangeService.FindFolders(new FolderId(WellKnownFolderName.MsgFolderRoot, mailbox), view);

                foreach (Folder folder in findFolderResults)
                {
                    if (folder.DisplayName == "Sent Items")
                    {
                        //Adding attachments to reply mail
                        EmailMessage reply = responseMessage.Save(folder.Id);
                        foreach (string attachment in attachments)
                        {
                            reply.Attachments.AddFileAttachment(attachment);
                        }
                        reply.Update(ConflictResolutionMode.AlwaysOverwrite);

                        //Sending mail and saving to sent Items
                        reply.SendAndSaveCopy(folder.Id);
                    }
                }
            }

            else
            {
                FolderView view = new FolderView(10000);
                view.PropertySet = new PropertySet(BasePropertySet.IdOnly);
                view.PropertySet.Add(FolderSchema.DisplayName);
                view.Traversal = FolderTraversal.Deep;
                Mailbox            mailbox           = new Mailbox(sender);
                FindFoldersResults findFolderResults = objExchangeService.FindFolders(new FolderId(WellKnownFolderName.MsgFolderRoot, mailbox), view);

                foreach (Folder folder in findFolderResults)
                {
                    if (folder.DisplayName == "Sent Items")
                    {
                        responseMessage.SendAndSaveCopy(folder.Id);
                    }
                }
            }
        }