Exemplo n.º 1
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            MailMessage mail = new MailMessage();

            mail.To.Add(ToAddress.Get(context));

            mail.From = new MailAddress(FromAddress.Get(context));

            mail.Subject = Subject.Get(context);


            mail.Body = Body.Get(context);

            mail.IsBodyHtml = true;
            SmtpClient smtp = new SmtpClient();

            Action action = () => {
                ManualResetEvent manualResetEvent = new ManualResetEvent(false);
                smtp.SendCompleted += (o, args) => {
                    manualResetEvent.Set();
                    Debug.WriteLine("Send Mail Completed");
                };
                smtp.SendAsync(mail, null);
                manualResetEvent.WaitOne(TimeSpan.FromSeconds(30));
            };

            context.UserState = action;

            return(action.BeginInvoke(callback, state));
        }
Exemplo n.º 2
0
        /// <summary>
        /// SendEmail method useful for get email and prepare email template to send to customer
        /// </summary>
        private void SendEmail()
        {
            tracingService.Trace("Entered EmailSender.SendEmail()");
            try
            {
                templateName = EmailTemplateName.Get(executionContext);
                queryString  = ToAddress.Get(executionContext);
                category     = Category.Get(executionContext);

                tracingService.Trace("EmailSender.SendEmail(), Template Name:{0} InPutEmailString: {1}, Category: {2}", queryString, templateName, category);

                if (!string.IsNullOrEmpty(templateName) && !string.IsNullOrEmpty(queryString))
                {
                    EntityCollection emails = null;
                    if (queryString.TrimStart().StartsWith("<"))
                    {
                        emails = GetEmailsByFetchXML();
                    }
                    else
                    {
                        emails = GetEmailByString();
                    }

                    if (null != emails && emails.Entities.Count > 0)
                    {
                        PrepareEmail(emails);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }