Beispiel #1
0
        private static void Main()
        {
            // create the email template
            var template = new EmailTemplate("Test");
            dynamic dtemplate = template;
            dtemplate.To = "*****@*****.**";
            dtemplate.Message = "Hello, non-asp.net world! ";
            dtemplate.Test = "test property";
            dtemplate.SubjectSuffix = DateTime.Now.ToShortTimeString();
            dtemplate.Values = new[] {"one", "two", "three"};
            template.Attach(@"c:\tmp\test2.log");
            template.Attach(@"c:\tmp\cat.jpg", "CatImageId"); // TODO: put in progam folder

            // serialize and deserialize the email template
            var serializerSettings = new JsonSerializerSettings
            {
                Converters = new List<JsonConverter>
                {
                    new AttachmentReadConverter(true)
                }
            };
            var serializedTemplate = JsonConvert.SerializeObject(template, Formatting.Indented, serializerSettings);
            Console.WriteLine(serializedTemplate);
            Console.WriteLine("serialized size: {0}", serializedTemplate.Length);
            var deserializedTemplate = JsonConvert.DeserializeObject<EmailTemplate>(serializedTemplate, serializerSettings);

            // send the email template
            var engines = new ViewEngineCollection
            {
                new ResourceRazorViewEngine(typeof (Program).Assembly, @"ResourceSample.Resources.Views")
            };
            var service = new SmtpMessagingService(engines);
            service.Send(deserializedTemplate);
        }
Beispiel #2
0
        private static void Main()
        {
            // create the email template
            var     template  = new EmailTemplate("Test");
            dynamic dtemplate = template;

            dtemplate.To            = "*****@*****.**";
            dtemplate.Message       = "Hello, non-asp.net world! ";
            dtemplate.Test          = "test property";
            dtemplate.SubjectSuffix = DateTime.Now.ToShortTimeString();
            dtemplate.Values        = new[] { "one", "two", "three" };
            template.Attach(@"c:\tmp\test2.log");
            template.Attach(@"c:\tmp\cat.jpg", "CatImageId"); // TODO: put in progam folder

            // serialize and deserialize the email template
            var serializerSettings = new JsonSerializerSettings
            {
                Converters = new List <JsonConverter>
                {
                    new AttachmentReadConverter(true)
                }
            };
            var serializedTemplate = JsonConvert.SerializeObject(template, Formatting.Indented, serializerSettings);

            Console.WriteLine(serializedTemplate);
            Console.WriteLine("serialized size: {0}", serializedTemplate.Length);
            var deserializedTemplate = JsonConvert.DeserializeObject <EmailTemplate>(serializedTemplate, serializerSettings);

            // send the email template
            var engines = new ViewEngineCollection
            {
                new ResourceRazorViewEngine(typeof(Program).Assembly, @"ResourceSample.Resources.Views")
            };
            var service = new SmtpMessagingService(engines);

            service.Send(deserializedTemplate);
        }
Beispiel #3
0
        public void Attach_adds_attachment()
        {
            dynamic email = new EmailTemplate("Test");
            var fileStream = new FileStream(@"c:\tmp\test2.log", FileMode.Open);
            fileStream.Position = 0;
            var memoryStream = new MemoryStream();
            fileStream.CopyTo(memoryStream);
            //var attachment = new Attachment(new MemoryStream(), "name");
            var attachment = new Attachment(memoryStream, "name");
            email.Attach(attachment);
            ((EmailTemplate)email).Attachments.ShouldContain(attachment);

            Console.WriteLine(JsonConvert.SerializeObject(email, Formatting.Indented,
                new MemoryStreamJsonConverter()));
        }
Beispiel #4
0
        public void Attach_adds_attachment()
        {
            dynamic email      = new EmailTemplate("Test");
            var     fileStream = new FileStream(@"c:\tmp\test2.log", FileMode.Open);

            fileStream.Position = 0;
            var memoryStream = new MemoryStream();

            fileStream.CopyTo(memoryStream);
            //var attachment = new Attachment(new MemoryStream(), "name");
            var attachment = new Attachment(memoryStream, "name");

            email.Attach(attachment);
            ((EmailTemplate)email).Attachments.ShouldContain(attachment);

            Console.WriteLine(JsonConvert.SerializeObject(email, Formatting.Indented,
                                                          new MemoryStreamJsonConverter()));
        }
Beispiel #5
0
        public async Task SendPatientRegister(NewPatientReq req, MemoryStream positions)
        {
            var email = new EmailTemplate
            {
                To              = To,
                Bcc             = Bcc,
                Subject         = "EMECI - Registro de paciente",
                Title           = "Registro de paciente",
                TypeEmailToSend = EmailTemplate.TypeEmail.patientRegister,
                PatientReq      = req
            };

            email.Attach(new Attachment(positions, "PosicionesDeAcceso.pdf"));

            try
            {
                await email.SendAsync();
            }
            catch (Exception ex)
            {
                Log.Write($"EmailService, SendPatientRegister=> {ex.Message}");
            }
        }