示例#1
0
        protected override void Execute(CodeActivityContext context)
        {
            Microsoft.Office.Interop.Outlook.Application outlookApplication = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.MailItem    email = (Microsoft.Office.Interop.Outlook.MailItem)outlookApplication.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

            var    to       = To.Get(context);
            var    cc       = CC.Get(context);
            var    bcc      = BCC.Get(context);
            var    subject  = Subject.Get(context);
            string body     = (Body != null ?Body.Get(context) : null);
            string htmlbody = (HTMLBody != null ? HTMLBody.Get(context) : null);

            if (!string.IsNullOrEmpty(htmlbody))
            {
                body = htmlbody;
            }
            var attachments = Attachments.Get(context);
            var uiaction    = UIAction.Get(context);

            email.BodyFormat = Microsoft.Office.Interop.Outlook.OlBodyFormat.olFormatRichText;
            email.To         = to;
            email.Subject    = subject;
            email.HTMLBody   = body;
            email.CC         = cc;
            email.BCC        = bcc;

            if (attachments != null && attachments.Count() > 0)
            {
                foreach (var attachment in attachments)
                {
                    if (!string.IsNullOrEmpty(attachment))
                    {
                        email.Attachments.Add(attachment, Microsoft.Office.Interop.Outlook.OlAttachmentType.olByValue, 100000, Type.Missing);
                    }
                }
            }
            if (uiaction == "Show")
            {
                email.Display(true);
            }
            //else if(uiaction == "SendVisable")
            //{
            //    email.Display(true);
            //    email.Send();
            //}
            else
            {
                email.Send();
            }
            if (EMail != null)
            {
                EMail.Set(context, new email(email));
            }
        }