Пример #1
0
 private void btnMail_Click(object sender, EventArgs e)
 {
     CreatePDF();
     MailAddress from = null;
     MailAddress to = null;
     if (!string.IsNullOrEmpty(tblRazonSocial.Rows[0]["CorreoRAZ"].ToString()))
     {
         from = new MailAddress(tblRazonSocial.Rows[0]["CorreoRAZ"].ToString());
     }
     else
     {
         MessageBox.Show("Debe ingresar una dirección de correo en los datos de la empresa", "TREND", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     if (!string.IsNullOrEmpty(tblCliente.Rows[0]["CorreoCLI"].ToString()))
     {
         to = new MailAddress(tblCliente.Rows[0]["CorreoCLI"].ToString());
     }
     else
     {
         to = new MailAddress("*****@*****.**");
     }
     var mailMessage = new MailMessage(from, to);
     mailMessage.Subject = "Your subject here";
     mailMessage.IsBodyHtml = true;
     //    mailMessage.Body = "<span style='font-size: 12pt; color: red;'>My HTML formatted body</span>";
     mailMessage.Attachments.Add(new Attachment(@"c:\windows\temp\output.pdf"));
     var filename = @"C:\Windows\Temp\message.eml";
     //save the MailMessage to the filesystem
     mailMessage.Save(filename); // utilizo el metodo save de la clase MailUtility en Utilitarios.cs
     //Open the file with the default associated application registered on the local machine
     Process.Start(filename);
 }
Пример #2
0
        public void SaveHtml()
        {
            MailMessage testMail = new MailMessage();
            testMail.To.Add(new MailAddress("*****@*****.**"));
            testMail.From = new MailAddress("*****@*****.**");
            testMail.Subject = "I am subject";
            testMail.Body = "<head>Jason Lee</head>";
            testMail.IsBodyHtml = true;

            testMail.Save(@"c:\Temp\html.eml");
        }
Пример #3
0
        public void Dundee()
        {
            MailMessage testMail = new MailMessage();
            testMail.To.Add(new MailAddress("*****@*****.**"));
            testMail.From = new MailAddress("*****@*****.**");
            testMail.Subject = "I am subject";

            String htmlBody = "郵件";
            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);
            htmlView.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;

            testMail.AlternateViews.Add(htmlView);
            testMail.Save(@"c:\Temp\jason.eml");
        }
Пример #4
0
        public void FileToEmailClientViaMailMessage()
        {
            string testDataFilePath = @"..\..\Data\test.txt";

            //string mailAddress = WindowsIdentity.GetCurrent().Name;
            string mailAddress = UserPrincipal.Current.EmailAddress;
            var mailMessage = new MailMessage();
            mailMessage.From = new MailAddress(mailAddress);
            mailMessage.Subject = String.Format("File {0} attached", Path.GetFileName(testDataFilePath));
            mailMessage.IsBodyHtml = false;
            //mailMessage.Body = "<span style='font-size: 12pt; color: red;'>My HTML formatted body</span>";
            mailMessage.Attachments.Add(new Attachment(testDataFilePath));

            var filename = Path.Combine(Path.GetTempPath(), "mymessage.eml");
            mailMessage.Save(filename);
            Process.Start(filename);
        }
Пример #5
0
        public void SaveHtmlWithImage()
        {
            MailMessage testMail = new MailMessage();
            testMail.To.Add(new MailAddress("*****@*****.**"));
            testMail.From = new MailAddress("*****@*****.**");
            testMail.Subject = "I am subject";

            String htmlBody = "<img src=\"cid:uniqueId\" />";
            AlternateView htmlView = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);
            htmlView.TransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;

            LinkedResource image = new LinkedResource(@"c:\temp\Ascent.jpg");
            image.ContentId = "uniqueId";
            htmlView.LinkedResources.Add(image);

            testMail.AlternateViews.Add(htmlView);
            testMail.Save(@"c:\Temp\testemail.eml");
        }
Пример #6
0
        public static void SendAttachment(string from, string subject, string body, string attachmentPath)
        {
            using (var mailMessage = new MailMessage())
            {
                mailMessage.From = new MailAddress(from);
                mailMessage.Subject = subject;
                mailMessage.IsBodyHtml = true;
                mailMessage.Body = Path.GetFileName(attachmentPath) ?? subject;

                mailMessage.Attachments.Add(new Attachment(attachmentPath));

                var filename = $"{Path.GetFileName(attachmentPath)}.eml";

                //save the MailMessage to the filesystem
                mailMessage.Save(filename);

                //Open the file with the default associated application registered on the local machine
                Process.Start(filename);
            }
        }
Пример #7
0
        private void button2_Click(object sender, EventArgs e)
        {
            MailAddress from = new MailAddress("*****@*****.**");
            MailAddress to = new MailAddress("*****@*****.**");

            var mailMessage = new MailMessage(from, to);
              //  mailMessage.From = new MailAddress("*****@*****.**");
            mailMessage.Subject = "Your subject here";
            mailMessage.IsBodyHtml = true;
            mailMessage.Body = "<span style='font-size: 12pt; color: red;'>My HTML formatted body</span>";

            mailMessage.Attachments.Add(new Attachment(@"C:\enviado.xml"));

            var filename = @"C:\Windows\Temp\mymessage.eml";

            //save the MailMessage to the filesystem
            mailMessage.Save(filename);

            //Open the file with the default associated application registered on the local machine
            Process.Start(filename);
        }
Пример #8
0
        public void SavePlain()
        {
            MailMessage testMail = new MailMessage();
            testMail.To.Add(new MailAddress("*****@*****.**"));
            testMail.From = new MailAddress("*****@*****.**");
            testMail.Subject = "I am subject";
            testMail.Body = "Jason Lee";

            testMail.Attachments.Add(new Attachment(@"c:\temp\slide.jpg", MediaTypeNames.Image.Jpeg));
            testMail.Save(@"c:\Temp\plain.eml");
        }
Пример #9
0
        private void Send_Email(object sender, RoutedEventArgs e)
        {
            var message = new MailMessage();
            message.From = new MailAddress("*****@*****.**");
            message.BodyEncoding = System.Text.Encoding.UTF8;
            message.HeadersEncoding = System.Text.Encoding.UTF8;

            PhotosListBox.SelectedItems.Cast<ManagedImage>().ToList().ForEach(
                item => message.Attachments.Add(new Attachment(item.ImageSource))
            );

            // get temporary files
            var filename = String.Format("{0}.{1}", PathUtility.GetTempFileName(), "eml");
            var filenamemod = String.Format("{0}.{1}", PathUtility.GetTempFileName(), "eml");

            //save the MailMessage to the filesystem
            message.Save(filename);

            Regex replacer = new Regex("*****@*****.**");
            using (TextWriter writer = new StreamWriter(filenamemod))
            {
                using (StreamReader reader = new StreamReader(filename))
                {
                    while (!reader.EndOfStream)
                    {
                        string line = reader.ReadLine();
                        writer.WriteLine(replacer.Replace(line, ""));
                    }
                }
                writer.Flush();
            }

            //Open the file with the default associated application registered on the local machine
            Process.Start(filenamemod);

            // remove temporary file
            File.Delete(filename);
        }