private void m_pOk_Click(object sender, EventArgs e) { AddressList from = new AddressList(); from.Parse(m_pFrom.Text); AddressList to = new AddressList(); to.Parse(m_pTo.Text); Mime m = Mime.CreateSimple(from,to,m_pSubject.Text,m_pBodyText.Text,null); m_Message = m.ToStringData(); this.DialogResult = DialogResult.OK; }
/// <summary> /// Creates Mime message based on UI data. /// </summary> private Mime CreateMessage() { Mime m = new Mime(); MimeEntity texts_enity = null; MimeEntity attachments_entity = null; if(m_pAttachments.Items.Count > 0){ m.MainEntity.ContentType = MediaType_enum.Multipart_mixed; texts_enity = m.MainEntity.ChildEntities.Add(); texts_enity.ContentType = MediaType_enum.Multipart_alternative; attachments_entity = m.MainEntity; } else{ m.MainEntity.ContentType = MediaType_enum.Multipart_alternative; texts_enity = m.MainEntity; } // Main entity settings AddressList from = new AddressList(); from.Parse(m_pFrom.Text); m.MainEntity.From = from; AddressList to = new AddressList(); to.Parse("\"" + m_pFolder.User.FullName + "\" <" + m_pFolder.User.FullName + "@localhost>"); m.MainEntity.To = to; m.MainEntity.Subject = m_pSubject.Text; // Create text/plain entity MimeEntity text_entity = texts_enity.ChildEntities.Add(); text_entity.ContentType = MediaType_enum.Text_plain; text_entity.ContentType_CharSet = "utf-8"; text_entity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable; text_entity.DataText = m_pText.Text; // Create text/rtf entity MimeEntity rtfText_entity = texts_enity.ChildEntities.Add(); rtfText_entity.ContentType = MediaType_enum.Text_html; rtfText_entity.ContentType_CharSet = "utf-8"; rtfText_entity.ContentTransferEncoding = ContentTransferEncoding_enum.Base64; rtfText_entity.DataText = RtfToHtml(); // Create attachment etities if(attachments_entity != null){ foreach(ListViewItem item in m_pAttachments.Items){ MimeEntity attachment_entity = attachments_entity.ChildEntities.Add(); attachment_entity.ContentType = MediaType_enum.Application_octet_stream; attachment_entity.ContentTransferEncoding = ContentTransferEncoding_enum.Base64; attachment_entity.ContentDisposition = ContentDisposition_enum.Attachment; attachment_entity.ContentDisposition_FileName = Path.GetFileName(item.Tag.ToString()); attachment_entity.Data = File.ReadAllBytes(item.Tag.ToString()); } } return m; }