protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            recipientName    = RecipientName.Get(context);
            recipientEmail   = RecipientEmail.Get(context);
            subject          = Subject.Get(context);
            documentFilePath = DocumentFilePath.Get(context);
            sigX             = PositionX.Get(context);
            sigY             = PositionY.Get(context);

            anchorText = AnchorText.Get(context);
            offsetX    = OffsetX.Get(context);
            offsetY    = OffsetY.Get(context);

            if (anchorText != null && anchorText != "" && Path.GetExtension(documentFilePath) != ".pdf")
            {
                throw new FormatException("Can only use relative positioning on .pdf files");
            }

            LoadAuthentication(context);

            SendEnvelopeDelegate = new Action(SendEnvelope);
            return(SendEnvelopeDelegate.BeginInvoke(callback, state));
        }
        protected override void ExecuteWorkflowLogic()
        {
            var emailId = Email.Get(Context.ExecutionContext).Id;

            var email = Context.UserService.Retrieve("email", emailId, new ColumnSet("to"));

            var to           = email.Contains("to") ? email.GetAttributeValue <EntityCollection>("to") : new EntityCollection();
            var newRecipient = new Entity("activityparty")
            {
                ["addressused"] = RecipientEmail.Get(Context.ExecutionContext)
            };

            to.Entities.Add(newRecipient);

            email["to"] = to;

            Context.UserService.Update(email);

            if (SendAfterOperation.Get(Context.ExecutionContext))
            {
                base.ExecuteWorkflowLogic();
            }
        }
Example #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);

            //******** 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);
                }
            }
        }