Esempio n. 1
0
        protected override void Execute(CodeActivityContext context)
        {
            Application app = new Application();

            app.ActiveWindow();
            Outlook.MailItem mail;
            if (!(TemplatePath.Get(context).Contains(".oft") || TemplatePath.Get(context).Contains(".msg")))
            {
                throw new System.Exception("Invalid template format, please use a '.oft' or '.msg' template.");
            }
            mail = TemplatePath.Get(context) != ""?(app.CreateItemFromTemplate(TemplatePath.Get(context).Contains(":\\") ? TemplatePath.Get(context) : System.IO.Directory.GetCurrentDirectory() + '\\' + TemplatePath.Get(context)) as Outlook.MailItem):new MailItem();

            mail.Subject = String.IsNullOrEmpty(Subject.Get(context))?(String.IsNullOrEmpty(mail.Subject)?"Untitled":mail.Subject):Subject.Get(context);
            mail.To      = String.IsNullOrEmpty(To.Get(context))?mail.To:To.Get(context);
            mail.CC      = String.IsNullOrEmpty(Cc.Get(context))?mail.CC:Cc.Get(context);
            mail.BCC     = String.IsNullOrEmpty(Bcc.Get(context))?mail.BCC:Bcc.Get(context);
            if (String.IsNullOrEmpty(mail.To) && String.IsNullOrEmpty(mail.CC) && String.IsNullOrEmpty(mail.BCC))
            {
                throw new System.Exception("Error, there is no recepients specified");
            }

            mail.HTMLBody = mail.HTMLBody.Replace("{message}", Body.Get(context));
            mail.HTMLBody = mail.HTMLBody.Replace("{table}", DT.Get(context) != null?(DT.Get(context).Rows.Count > 0?GetHTMLTable(DT.Get(context)):""):"");
            mail.Send();
            app.GetNamespace("MAPI").SendAndReceive(true);

            var releaseResult = Marshal.ReleaseComObject(app);
        }
        /// <summary>
        ///     Transforms a text template that is specified in the TemplatePath property by calling the Visual Studio STextTemplatingService.
        /// </summary>
        /// <param name="context">The state of the current activity.</param>
        protected override void Execute(NativeActivityContext context)
        {
            // inject the template path at runtime if an explicit one doesn't exist.
            if (TemplatePath.Get(context) == null)
            {
                var symbolResolver  = context.GetExtension <SymbolResolver>();
                var edmParameterBag = symbolResolver[typeof(EdmParameterBag).Name] as EdmParameterBag;
                var ddlTemplatePath = edmParameterBag.GetParameter <string>(EdmParameterBag.ParameterName.DDLTemplatePath);

                if (String.IsNullOrEmpty(ddlTemplatePath))
                {
                    // TemplatePath must either be specified at design-time in the workflow file or at runtime, passed in through EdmParameterBag.
                    throw new ArgumentException(
                              String.Format(CultureInfo.CurrentCulture, Resources.DatabaseCreation_NoDDLTemplatePathSpecified, DisplayName));
                }

                TemplatePath.Set(context, ddlTemplatePath);
            }

            base.Execute(context);

            Debug.Assert(!String.IsNullOrEmpty(TemplateOutput), "DDL returned from SsdlToDdl template is null or empty...");
            if (TemplateOutput == null)
            {
                throw new InvalidOperationException(
                          String.Format(CultureInfo.CurrentCulture, Resources.DatabaseCreation_ErrorTemplateOutputNotSet, DisplayName));
            }

            DdlOutput.Set(context, TemplateOutput);
        }
        protected override void Execute(CodeActivityContext context)
        {
            String TO, CC, BCC, SUBJECT, BODY;

            if (TemplatePath.Get(context).Contains(".eml"))
            {
                Message emlMessage = ReadMessage(TemplatePath.Get(context).Contains(":\\") ? TemplatePath.Get(context) : System.IO.Directory.GetCurrentDirectory() + '\\' + TemplatePath.Get(context));
                TO      = emlMessage.To;
                CC      = emlMessage.CC;
                BCC     = emlMessage.BCC;
                SUBJECT = emlMessage.Subject;
                BODY    = String.IsNullOrEmpty(emlMessage.HTMLBody)?emlMessage.TextBody:emlMessage.HTMLBody;
            }
            else if (TemplatePath.Get(context).Contains(".oft") || TemplatePath.Get(context).Contains(".msg"))
            {
                try
                {
                    Outlook.Application app      = new Outlook.Application();
                    Outlook.MailItem    template = app.CreateItemFromTemplate(TemplatePath.Get(context).Contains(":\\") ? TemplatePath.Get(context) : System.IO.Directory.GetCurrentDirectory() + '\\' + TemplatePath.Get(context)) as Outlook.MailItem;
                    TO      = template.To;
                    CC      = template.CC;
                    BCC     = template.BCC;
                    SUBJECT = template.Subject;
                    BODY    = String.IsNullOrEmpty(template.HTMLBody) ? template.Body : template.HTMLBody;
                }
                catch
                {
                    throw new System.Exception("Error, .oft and .msg files can only be read if you have Outlook installed, try using a .eml as a template");
                }
            }
            else
            {
                throw new System.Exception("Invalid template format, please use a '.oft', '.msg', or '.eml' template.");
            }

            SUBJECT = String.IsNullOrEmpty(Subject.Get(context)) ? (String.IsNullOrEmpty(SUBJECT) ? "Untitled" : SUBJECT) : Subject.Get(context);
            TO      = String.IsNullOrEmpty(To.Get(context)) ? TO : To.Get(context);
            CC      = String.IsNullOrEmpty(Cc.Get(context)) ? CC : Cc.Get(context);
            BCC     = String.IsNullOrEmpty(Bcc.Get(context)) ? BCC : Bcc.Get(context);
            BODY    = BODY.Replace("{message}", String.IsNullOrEmpty(Body.Get(context))?"":Body.Get(context));
            BODY    = BODY.Replace("{table}", DT.Get(context) != null ? (DT.Get(context).Rows.Count > 0 ? GetHTMLTable(DT.Get(context)) : "") : "");
            MailMessage mail = new MailMessage(From.Get(context), TO, SUBJECT, BODY);

            mail.Bcc.Add(BCC);
            mail.IsBodyHtml = true;
            mail.CC.Add(CC);
            SmtpClient client = new SmtpClient
            {
                Port                  = Port.Get(context),
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                EnableSsl             = EnableSSL,
                Host                  = Server.Get(context),
                Credentials           = new System.Net.NetworkCredential(Email.Get(context), Password.Get(context)),
                Timeout               = 30000
            };

            client.Send(mail);
        }
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context,
                                                                                        CancellationToken cancellationToken, Application client)
        {
            List <string> inputs = Attachments.Select(x => x.Get(context)).ToList();

            var app = new Application(TemplatePath.Get(context), Subject?.Get(context), To?.Get(context), Cc?.Get(context), Bcc?.Get(context), Body?.Get(context), From?.Get(context), Port.Get(context), DT?.Get(context), EnableSSL, Server.Get(context), Email.Get(context), Password.Get(context), inputs);
            await Task.Run(() => app.SendMail());

            return(f => { });
        }
Esempio n. 5
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken, Application client)
        {
            List <string> inputs = Attachments.Select(x => x.Get(context)).ToList();

            if (!(TemplatePath.Get(context).Contains(".oft") || TemplatePath.Get(context).Contains(".msg")))
            {
                throw new System.Exception("Invalid template format, please use a '.oft' or '.msg' template.");
            }
            Application app = new Application();

            app.SendOutlook(TemplatePath.Get(context), Subject.Get(context), To.Get(context), Cc.Get(context), Bcc.Get(context), Body.Get(context), DT.Get(context), inputs);
            return(ctx => { });
        }
Esempio n. 6
0
        protected override void Execute(CodeActivityContext context)
        {
            var    templateString = TemplateString.Get(context);
            var    templatePath   = TemplatePath.Get(context);
            var    obj            = InputObject.Get(context);
            var    stubble        = new StubbleBuilder().Build();
            string output;

            if (!string.IsNullOrEmpty(templateString))
            {
                output = stubble.Render(templateString, obj);
            }
            else
            {
                using (StreamReader streamReader = new StreamReader(templatePath, Encoding.UTF8))
                {
                    output = stubble.Render(streamReader.ReadToEnd(), obj);
                }
            }


            Output.Set(context, output);
        }