public ConvertRtfToHtml ( string rtfText ) : string | ||
rtfText | string | |
return | string |
private void SendToSingleAddress(string sAddress) { //define email parameters SmtpClient smtp = new SmtpClient { Host = oProv.Host, Port = oProv.Port, DeliveryMethod = SmtpDeliveryMethod.Network, Credentials = new System.Net.NetworkCredential(oProv.User, oProv.PWD), EnableSsl = true }; MailMessage mail = new MailMessage { From = new MailAddress(oProv.User), Subject = oEmail.Subject, // Convert rtf text into html for email Body = mk.ConvertRtfToHtml(richTextBox.Rtf), IsBodyHtml = true }; if (lstAttach.Count > 0) { // Create the file attachment for this e-mail message. foreach (string file in lstAttach) { Attachment data = new Attachment(file, MediaTypeNames.Application.Octet); // Add time stamp information for the file. ContentDisposition disposition = data.ContentDisposition; disposition.CreationDate = System.IO.File.GetCreationTime(file); disposition.ModificationDate = System.IO.File.GetLastWriteTime(file); disposition.ReadDate = System.IO.File.GetLastAccessTime(file); // Add the file attachment to this e-mail message. mail.Attachments.Add(data); } } mail.Bcc.Add(new MailAddress(sAddress)); smtp.Send(mail); mail.Dispose(); smtp.Dispose(); }
private void button2_Click(object sender, EventArgs evnt) //gönderme işlemi { if (textBox1.Text != "" && textBox2.Text != "") { metinbaslangicIndex = 0; SmtpClient client = new SmtpClient(); MimeMessage message = new MimeMessage(); BodyBuilder builder = new BodyBuilder(); client.ServerCertificateValidationCallback = (s, c, h, e) => true; client.Connect("smtp.gmail.com", 465, SecureSocketOptions.SslOnConnect); client.Authenticate(login_user.Instance.Eposta, login_user.Instance.sifre); bool hata_varmı = false; bool loop = true; rtf = richTextBox1.Rtf; while (loop) { try { tut = ExtractImgRtf(rtf); } catch (Exception) { hata_varmı = true; } try { bool duplicate_engelleme = false; IMarkupConverter markupConverter = new MarkupConverter.MarkupConverter(); if (hata_varmı == false) { for (int i = 0; i < bfile.Count; i++) { if (bfile[i].bodyfile_string == tut && duplicate_engelleme == false) { duplicate_engelleme = true; string body = rtf.Substring(metinbaslangicIndex, startIndex - metinbaslangicIndex); metinbaslangicIndex = (endIndex + 12); var bodyfile = builder.LinkedResources.Add(bfile[i].file_name, bfile[i].bodyfile_byte); bodyfile.ContentId = MimeUtils.GenerateMessageId(); //try catch gelcek ve text html yerine textx döncek if error string html_body = markupConverter.ConvertRtfToHtml(body); builder.HtmlBody += html_body; builder.HtmlBody += string.Format(@"<img src=""cid:{0}"" width={1} height={2} > ", bodyfile.ContentId, width, height); } } duplicate_engelleme = false; } else { string body = rtf.Substring(metinbaslangicIndex, richTextBox1.Rtf.Length - metinbaslangicIndex); string html_body = markupConverter.ConvertRtfToHtml(body); builder.HtmlBody += html_body; loop = false; } } catch (Exception ht) { MessageBox.Show("Hata: " + ht); string body = richTextBox1.Text; builder.TextBody = body; loop = false; } } bool empty = !attachment_dondur.Any(); if (empty != true) { foreach (string yol in attachment_dondur) { builder.Attachments.Add(@"" + yol); } } bool mesaj_gittimi = true; try { message.From.Add(MailboxAddress.Parse(login_user.Instance.Eposta)); message.To.Add(MailboxAddress.Parse(textBox1.Text)); message.Subject = textBox2.Text; message.Body = builder.ToMessageBody(); client.Send(message); } catch (Exception ht) { MessageBox.Show("Mail yollanırken hata ile karşılaşıldı: " + ht); mesaj_gittimi = false; } finally { startIndex = 0; endIndex = 0; metinbaslangicIndex = 0; bfile.Clear(); richTextBox1.Clear(); } if (mesaj_gittimi == true) { MessageBox.Show("Mesaj Gönderildi."); } } else { if (textBox1.Text == "") { textBox1.Text = "Gönderilecek kişi ksmı boş geçilemez."; } if (textBox2.Text == "") { textBox2.Text = "Konu ksmı boş geçilemez."; } MessageBox.Show("Lütfen Her bir bölümü doldurduğunuza emin olunuz..."); } }