Exemple #1
0
        public override void Execute(IEmailItem emailItem = null, int?lastExitCode = null)
        {
            if (!AppliesTo(emailItem, lastExitCode))
            {
                return;
            }

            // AppliesTo() will return false, if emailItem is null.
            // ReSharper disable once PossibleNullReferenceException
            if (BodyFormat.Text == emailItem.Message.Body.BodyFormat)
            {
                var sb = new StringBuilder();
                sb.Append(emailItem.Message.GetBody());
                sb.AppendLine();
                sb.AppendLine();
                sb.Append(Text);
                emailItem.Message.SetBody(sb.ToString());
            }

            if (BodyFormat.Rtf == emailItem.Message.Body.BodyFormat)
            {
                var messageRtf = new RtfDocument(emailItem.Message.GetBody());
                var mergeRtf   = new RtfDocument(Rtf);

                if (messageRtf.Merge(mergeRtf))
                {
                    emailItem.Message.SetBody(messageRtf.Content);
                }
            }

            if (BodyFormat.Html == emailItem.Message.Body.BodyFormat)
            {
                var messageDoc = new HtmlDocument();
                messageDoc.LoadHtml(emailItem.Message.GetBody());

                var disclaimerDoc = new HtmlDocument();
                disclaimerDoc.LoadHtml(Html);

                var messageBodyNode    = messageDoc.DocumentNode.SelectSingleNode("//body");
                var disclaimerBodyNode = disclaimerDoc.DocumentNode.SelectSingleNode("//body");

                var brNode = messageDoc.CreateElement("br");

                messageBodyNode.AppendChild(brNode);

                messageBodyNode.AppendChildren(disclaimerBodyNode.ChildNodes);

                emailItem.Message.SetBody(messageDoc.DocumentNode.InnerHtml);
            }

            if (null == Handlers || Handlers.Count <= 0)
            {
                return;
            }

            foreach (var handler in Handlers)
            {
                handler.Execute(emailItem, lastExitCode);
            }
        }
        public override void Execute(IEmailItem emailItem = null, int?lastExitCode = null)
        {
            if (AppliesTo(emailItem, lastExitCode))
            {
                if (BodyFormat.Text == emailItem.Message.Body.BodyFormat)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(emailItem.Message.GetBody());
                    sb.AppendLine();
                    sb.AppendLine();
                    sb.Append(Text);
                    emailItem.Message.SetBody(sb.ToString());
                }

                if (BodyFormat.Rtf == emailItem.Message.Body.BodyFormat)
                {
                    var messageRtf = new RtfDocument(emailItem.Message.GetBody());
                    var mergeRtf   = new RtfDocument(Rtf);

                    if (messageRtf.Merge(mergeRtf))
                    {
                        emailItem.Message.SetBody(messageRtf.Content);
                    }
                }

                if (BodyFormat.Html == emailItem.Message.Body.BodyFormat)
                {
                    var messageDoc = new HtmlDocument();
                    messageDoc.LoadHtml(emailItem.Message.GetBody());

                    var disclaimerDoc = new HtmlDocument();
                    disclaimerDoc.LoadHtml(Html);

                    var messageBodyNode    = messageDoc.DocumentNode.SelectSingleNode("//body");
                    var disclaimerBodyNode = disclaimerDoc.DocumentNode.SelectSingleNode("//body");

                    var brNode = messageDoc.CreateElement("br");

                    messageBodyNode.AppendChild(brNode);

                    messageBodyNode.AppendChildren(disclaimerBodyNode.ChildNodes);

                    emailItem.Message.SetBody(messageDoc.DocumentNode.InnerHtml);
                }

                if (null != Handlers && Handlers.Count > 0)
                {
                    foreach (IHandler handler in Handlers)
                    {
                        handler.Execute(emailItem, lastExitCode);
                    }
                }
            }
        }
        public override void Execute(IEmailItem emailItem = null, int? lastExitCode = null)
        {
            if (AppliesTo(emailItem, lastExitCode))
            {
                if (BodyFormat.Text == emailItem.Message.Body.BodyFormat)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append(emailItem.Message.GetBody());
                    sb.AppendLine();
                    sb.AppendLine();
                    sb.Append(Text);
                    emailItem.Message.SetBody(sb.ToString());
                }

                if (BodyFormat.Rtf == emailItem.Message.Body.BodyFormat)
                {
                    var messageRtf = new RtfDocument(emailItem.Message.GetBody());
                    var mergeRtf = new RtfDocument(Rtf);

                    if (messageRtf.Merge(mergeRtf))
                    {
                        emailItem.Message.SetBody(messageRtf.Content);
                    }
                }

                if (BodyFormat.Html == emailItem.Message.Body.BodyFormat)
                {
                    var messageDoc = new HtmlDocument();
                    messageDoc.LoadHtml(emailItem.Message.GetBody());

                    var disclaimerDoc = new HtmlDocument();
                    disclaimerDoc.LoadHtml(Html);

                    var messageBodyNode = messageDoc.DocumentNode.SelectSingleNode("//body");
                    var disclaimerBodyNode = disclaimerDoc.DocumentNode.SelectSingleNode("//body");

                    var brNode = messageDoc.CreateElement("br");

                    messageBodyNode.AppendChild(brNode);

                    messageBodyNode.AppendChildren(disclaimerBodyNode.ChildNodes);

                    emailItem.Message.SetBody(messageDoc.DocumentNode.InnerHtml);
                }

                if (null != Handlers && Handlers.Count > 0)
                {
                    foreach (IHandler handler in Handlers)
                    {
                        handler.Execute(emailItem, lastExitCode);
                    }
                }
            }
        }