예제 #1
0
        public HttpResponseMessage PostEmailGenerate(EmailSendDetail emailSendDetail)
        {
            HtmlUtility utility = HtmlUtilityReturn(emailSendDetail);

            var emailFinal = utility.ToEmailMessage();

            var memoryStream = new MemoryStream();
            emailFinal.SaveToStream(memoryStream);
            string emailString = LocalEncoding.GetString(memoryStream.ToArray());

            var emailDetailsTopicResult = new EmailDetailsTopicResult()
                                              {
                                                  Title =
                                                      emailSendDetail.MailBatchLabel ??
                                                      DateTime.Now.ToString(CultureInfo.InvariantCulture),
                                                  CreateDate = DateTime.UtcNow,
                                                  EmailMime = emailString,
                                                  EmailSubject = !String.IsNullOrEmpty(emailSendDetail.SubjectHtml)
                                                                     ? emailSendDetail.SubjectHtml
                                                                     : ConvertStringToHtml(emailSendDetail.Subject)

                                              };
               EmailDetailsTopicManager.I.Insert(emailDetailsTopicResult);

               List<AttendeesShortForEmail> attendeesShorts = Utils.GetAttendeesShortBySql(emailSendDetail.SqlStatement);
            foreach (var rec in attendeesShorts)
            {
                var emailDetails = new EmailDetailsResult()
                {
                    EmailDetailsTopicId = emailDetailsTopicResult.Id,
                    AttendeesId = rec.Id,
                    EmailDetailsGuid = Guid.NewGuid(),
                    EmailTo = rec.Email
                };
                EmailDetailsManager.I.Insert(emailDetails);
            }

            var httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK);

            //emailFinal.SaveToFile("e:\\temp\\mailSave.txt", true);

            //var emailMergeField =
            //    new EmailMergeField
            //        {
            //            SubjectHtml = !String.IsNullOrEmpty(emailSendDetail.SubjectHtml)
            //                              ? emailSendDetail.SubjectHtml
            //                              : ConvertStringToHtml(emailSendDetail.Subject, 27),
            //            EmailHtml = emailSendDetail.EmailHtml,
            //            PreviousYearsStatusHtml = ""
            //        };

            //var emailMergeFields =
            //    new List<EmailMergeField>
            //        {
            //            emailMergeField
            //        };

            //HttpResponseMessage httpResponseMessage =
            //   emailFinal.SendMailMerge(emailMergeFields)
            //       ? new HttpResponseMessage(HttpStatusCode.OK)
            //       : Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed,
            //                                     emailFinal.LastException().Message);

            return httpResponseMessage;
        }
예제 #2
0
        public HttpResponseMessage PostEmailPreview(EmailSendDetail emailSendDetail)
        {
            string httpProtocol = HttpContext.Current.Request.IsSecureConnection
                                      ? "https://"
                                      : "http://";
            var baseUrl = string.Format("{0}{1}", httpProtocol, HttpContext.Current.Request.Url.Authority);

            HtmlUtility utility = HtmlUtilityReturn(emailSendDetail);

            var emailFinal = utility.ToEmailMessage();
            //emailFinal.SaveToFile("e:\\temp\\mailSave.txt", true);
            //string baseUnSubscribeUrl = "http://*****:*****@"," @ "), // add spaces so these emails don't get hyperlinked
                        FromEmailAddress = emailFinal.FromAddress.Replace("@", " @ "),
                        EmailTrackingId = emailDetails.EmailDetailsGuid.ToString(),
                        BaseUrlEmailPage = emailSendDetail.EmailUrl,
                        BaseUrlSvcc = baseUrl
                    };

            var emailMergeFields =
                new List<EmailMergeField>
                    {
                        emailMergeField
                    };

            emailFinal.Logging = true;
            emailFinal.LogInMemory = true;

            HttpResponseMessage httpResponseMessage =
               emailFinal.SendMailMerge(emailMergeFields)
                   ? new HttpResponseMessage(HttpStatusCode.OK)
                   : Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed,
                                                 emailFinal.LastException().Message);

            // var str = emailFinal.Log.ToString();
            //System.IO.File.AppendAllText("e:\\temp\\_log.txt", str);

            return httpResponseMessage;
        }