/// <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);
                }
            }
        }
Пример #2
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);
                    }
                }
            }
        }
Пример #3
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);
                    }
                }
            }
        }