Exemplo n.º 1
0
        public FileResult Email(TestViewModel data)
        {
            var model = new RegistrationViewModel
            {
                FirstName       = "Olav",
                LastName        = "Hinz",
                EMail           = "*****@*****.**",
                Street          = "Auenstr.",
                Number          = "35",
                City            = "München",
                PostalCode      = "80469",
                Country         = "Deutschland",
                Studienrichtung = "Fotodesign",
            };

            // pdf erzeugen
            // html rendern
            // streamen und dann als Attachment anhängen
            var stream = new MemoryStream();



            // E-Mail senden
            var email = new ApplicationEmail("Registration");

            email.To          = model.EMail;
            email.From        = "*****@*****.**";
            email.Subject     = string.Format("Ihre Bewerbung für {0}", model.Studienrichtung);
            email.Application = model;
            email.Id          = "123";
            email.Year        = "2017/18";

            ViewBag.Styles = data.Styles;

            var         html = this.RenderViewToString("_PrintOut", email);
            PdfDocument pdf  = PdfGenerator.GeneratePdf(html, PageSize.A4);

            //pdf.Save("document.pdf");
            pdf.Save(stream, false);


            // Stream zurücksetzen
            stream.Position = 0;

            return(File(stream, "text/pdf", "Ausdruck.pdf"));
        }
Exemplo n.º 2
0
        private static void LoadNotificationTemplate(Order o, string OrderNumber)
        {
            Guid TemplateId = Guid.Empty;

            try
            {
                var orderFromEmailAddress = new MailAddress(ConfigurationManager.AppSettings["DigiOrderNotificationEmail"], ConfigurationManager.AppSettings["DigiOrderNotificationName"]);
                Guid.TryParse(Convert.ToString(ConfigurationManager.AppSettings["DigitalFileEmailTemplate"]), out TemplateId);
                int uploadedImgCount = Orders.GetS3UploadedImagesCount("customer", o.OrderId);

                if (TemplateId == Guid.Empty)
                {
                    throw new Exception("Please add digital order template id");
                }
                ApplicationEmail email = ApplicationEmails.Get(TemplateId);
                StringBuilder    sb    = new StringBuilder();
                sb.Append(email.BodyContent);
                string orderDetail = ConfigurationManager.AppSettings["FrontBaseURL"] + "/account/order.aspx?id=" + o.OrderId;
                sb.Replace("##OrderDetail##", orderDetail);
                if (uploadedImgCount > 0)
                {
                    sb.Replace("##Count##", Convert.ToString(uploadedImgCount));
                }
                else
                {
                    sb.Replace("##Count##", string.Empty);
                }
                sb.Replace("##OrderNumber##", OrderNumber);
                sb.Replace("##OrderDate##", o.Timestamp.ToString("MM/dd/yyyy"));
                sb.Replace("##OrderEmail##", o.Email);
                sb.Replace("##ordernumber##", OrderNumber);
                var orderEmail = new MailMessage();
                orderEmail.From = orderFromEmailAddress;
                orderEmail.To.Add(o.Email);
                orderEmail.Subject    = email.Subject;
                orderEmail.IsBodyHtml = true;
                orderEmail.Body       = sb.ToString();
                bool hasEmailSent = SendEmail(orderEmail);
            }
            catch (Exception ex)
            {
                InsertLog("\nDatetime:" + DateTime.Now + "\tError : Error when reading email template from system email for template id :=" + TemplateId + "\n" + ex.Message + " " + (ex.InnerException == null ? string.Empty : ex.InnerException.Message));
            }
        }
Exemplo n.º 3
0
        public static void ExecuteEmail(string cmd)
        {
            //ApplicationEmail AppEmail = new ApplicationEmail();
            clsMetodosBanco  banco = new clsMetodosBanco();
            MySqlDataReader  DataReader;
            DataSet          DataSet;
            ApplicationEmail AppEmail   = new ApplicationEmail();
            List <string>    MeusEmails = new List <string>();
            EmailAtual       meuEmail   = new EmailAtual();


            switch (cmd)
            {
            //Carregar email antes de utilizar
            case "carregar email":
                try
                {
                    AppEmail.Show();
                    DataReader = banco.RetornaLogin();
                    if (AppEmail == null)
                    {
                        if (DataReader.Read())
                        {
                            AppEmail.StartReceiving(DataReader["email"].ToString(), DataReader["senha"].ToString());
                            Speaker.Speak("Email carregado com sucesso.");
                        }
                        AppEmail.Dispose();
                    }
                    else
                    {
                        if (DataReader.Read())
                        {
                            AppEmail.StartReceiving(DataReader["email"].ToString(), DataReader["senha"].ToString());
                        }
                        Speaker.Speak("Email carregado com sucesso.");
                    }
                }
                catch (Exception ex)
                {
                    Speaker.Speak("Ocorreu um erro na leitura dos emails.");
                    MessageBox.Show(ex.ToString());
                }
                break;

            //Leitura de emails da ultima hora
            case "ler email":
                try
                {
                    DataReader = banco.RetornaEmail();
                    while (DataReader.Read())
                    {
                        MeusEmails.Add("De: " + DataReader.GetString(1).Replace("<", "").Replace(">", "") + "Titulo: " + DataReader.GetString(2));
                    }

                    foreach (string t in MeusEmails)
                    {
                        Speaker.Speak(t);
                        Thread.Sleep(9000);
                    }
                }
                catch (Exception ex)
                {
                    Speaker.Speak("Ocorreu um erro na leitura dos emails.");
                    MessageBox.Show(ex.ToString());
                }

                break;

            case "meu email":
                meuEmail.Show();
                break;

            case "fechar meu email":
                meuEmail.Close();
                break;
            }
        }
Exemplo n.º 4
0
        /*
         * [HttpPost]
         * public ActionResult Confirm(RegistrationViewModel model, string submitButton)
         * {
         *  if (submitButton.Equals("abschicken"))
         *  {
         *      // In Datenbank speichern
         *
         *      // E-Mail senden
         *
         *      return View("ThankYou");
         *  }
         *
         *  return View("Index", model);
         * }
         */

        public ActionResult Save()
        {
            // In Datenbank speichern
            var model = (RegistrationViewModel)Session["Application"];

            var db = new PortfolioDbContext();

            var c = 0;

            if (model.Studienrichtung.Equals("Fotodesign"))
            {
                c = 1;
            }
            if (model.Studienrichtung.Equals("Industriedesign"))
            {
                c = 2;
            }
            if (model.Studienrichtung.Equals("Kommunikationsdesign"))
            {
                c = 3;
            }

            bool hist = model.Pruefung_schon_mal_gemacht.Equals("ja");

            var  c2 = 0;
            bool b  = false;

            if (hist)
            {
                if (model.Studienrichtung_schon_mal_Aufnahmepruefung.Equals("Fotodesign"))
                {
                    c2 = 1;
                }
                if (model.Studienrichtung_schon_mal_Aufnahmepruefung.Equals("Industriedesign"))
                {
                    c2 = 2;
                }
                if (model.Studienrichtung_schon_mal_Aufnahmepruefung.Equals("Kommunikationsdesign"))
                {
                    c2 = 3;
                }

                b = model.Pruefung_schon_mal_bestanden.Equals("ja");
            }

            var appl = new PortfolioApplication
            {
                FirstName        = model.FirstName,
                LastName         = model.LastName,
                Curriculum       = c,
                EMail            = model.EMail,
                Phone            = model.Phone,
                Street           = model.Street,
                Number           = model.Number,
                City             = model.City,
                PostalCode       = model.PostalCode,
                Country          = model.Country,
                RegistrationDate = DateTime.Now,
                HasPrevAppl      = hist,
                PrevApplSem      = hist ? model.Jahreszahl : null,
                PrevCurriculum   = hist ? (int?)c2 : null,
                ApplPassed       = hist ? (bool?)b : (bool?)null,
                HasConfirmed     = true
            };

            db.Applications.Add(appl);
            db.SaveChanges();


            // pdf erzeugen
            // html rendern

            /*
             * var doc = new PdfDocument();
             * // html als string übergeben
             *
             * var html = this.RenderViewToString("_PrintOut", model);
             * var pageSettings = new PdfPageSettings
             * {
             *  Height = 297F,
             *  Width = 210F,
             *  Orientation = PdfPageOrientation.Portrait,
             * };
             * var pdfLayoutFormat = new PdfHtmlLayoutFormat();
             *
             *
             * Thread thread = new Thread(() =>
             * {
             *  doc.LoadFromHTML(html, true, pageSettings, pdfLayoutFormat);
             * });
             *   thread.SetApartmentState(ApartmentState.STA);
             *   thread.Start();
             *   thread.Join();
             */


            // streamen und dann als Attachment anhängen
            var stream = new MemoryStream();
            //doc.SaveToStream(stream);

            /*
             * var path = Path.Combine(Path.GetTempPath(), "Ausdruck.pdf");
             * doc.SaveToFile(path);
             */



            // E-Mail senden
            var email = new ApplicationEmail("Registration");

            email.To          = model.EMail;
            email.From        = "*****@*****.**";
            email.Subject     = string.Format("Ihre Bewerbung für {0}", model.Studienrichtung);
            email.Application = model;
            email.Id          = appl.Id.ToString();
            email.Year        = "2017/18";

            var         html = this.RenderViewToString("_PrintOut", email);
            PdfDocument pdf  = PdfGenerator.GeneratePdf(html, PageSize.A4);

            //pdf.Save("document.pdf");
            pdf.Save(stream, false);


            // Stream zurücksetzen
            stream.Position = 0;
            email.Attach(new Attachment(stream, "Aufkleber.pdf", System.Net.Mime.MediaTypeNames.Application.Pdf));
            //email.Attach(new Attachment(path, System.Net.Mime.MediaTypeNames.Application.Pdf));

            email.Send();


            return(View("ThankYou"));
        }