/// <summary> /// Creates simple mime message with attachments. /// </summary> /// <param name="from">Header field From: value.</param> /// <param name="to">Header field To: value.</param> /// <param name="subject">Header field Subject: value.</param> /// <param name="bodyText">Body text of message. NOTE: Pass null is body text isn't wanted.</param> /// <param name="bodyHtml">Body HTML text of message. NOTE: Pass null is body HTML text isn't wanted.</param> /// <param name="attachmentFileNames">Attachment file names. Pass null if no attachments. NOTE: File name must contain full path to file, for example: c:\test.pdf.</param> /// <returns></returns> public static Mime CreateSimple(AddressList from,AddressList to,string subject,string bodyText,string bodyHtml,string[] attachmentFileNames) { Mime m = new Mime(); MimeEntity mainEntity = m.MainEntity; mainEntity.From = from; mainEntity.To = to; mainEntity.Subject = subject; // There are no atachments if(attachmentFileNames == null || attachmentFileNames.Length == 0){ // If bodyText and bodyHtml both specified if(bodyText != null && bodyHtml != null){ mainEntity.ContentType = MediaType_enum.Multipart_alternative; MimeEntity textEntity = mainEntity.ChildEntities.Add(); textEntity.ContentType = MediaType_enum.Text_plain; textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable; textEntity.DataText = bodyText; MimeEntity textHtmlEntity = mainEntity.ChildEntities.Add(); textHtmlEntity.ContentType = MediaType_enum.Text_html; textHtmlEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable; textHtmlEntity.DataText = bodyHtml; } // There is only body text else if(bodyText != null){ MimeEntity textEntity = mainEntity; textEntity.ContentType = MediaType_enum.Text_plain; textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable; textEntity.DataText = bodyText; } // There is only body html text else if(bodyHtml != null){ MimeEntity textHtmlEntity = mainEntity; textHtmlEntity.ContentType = MediaType_enum.Text_html; textHtmlEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable; textHtmlEntity.DataText = bodyHtml; } } // There are attachments else{ mainEntity.ContentType = MediaType_enum.Multipart_mixed; // If bodyText and bodyHtml both specified if(bodyText != null && bodyHtml != null){ MimeEntity multiPartAlternativeEntity = mainEntity.ChildEntities.Add(); multiPartAlternativeEntity.ContentType = MediaType_enum.Multipart_alternative; MimeEntity textEntity = multiPartAlternativeEntity.ChildEntities.Add(); textEntity.ContentType = MediaType_enum.Text_plain; textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable; textEntity.DataText = bodyText; MimeEntity textHtmlEntity = multiPartAlternativeEntity.ChildEntities.Add(); textHtmlEntity.ContentType = MediaType_enum.Text_html; textHtmlEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable; textHtmlEntity.DataText = bodyHtml; } // There is only body text else if(bodyText != null){ MimeEntity textEntity = mainEntity.ChildEntities.Add(); textEntity.ContentType = MediaType_enum.Text_plain; textEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable; textEntity.DataText = bodyText; } // There is only body html text else if(bodyHtml != null){ MimeEntity textHtmlEntity = mainEntity.ChildEntities.Add(); textHtmlEntity.ContentType = MediaType_enum.Text_html; textHtmlEntity.ContentTransferEncoding = ContentTransferEncoding_enum.QuotedPrintable; textHtmlEntity.DataText = bodyHtml; } foreach(string fileName in attachmentFileNames){ MimeEntity attachmentEntity = mainEntity.ChildEntities.Add(); attachmentEntity.ContentType = MediaType_enum.Application_octet_stream; attachmentEntity.ContentDisposition = ContentDisposition_enum.Attachment; attachmentEntity.ContentTransferEncoding = ContentTransferEncoding_enum.Base64; attachmentEntity.ContentDisposition_FileName = Core.GetFileNameFromPath(fileName); attachmentEntity.DataFromFile(fileName); } } return m; }
/// <summary> /// Creates simple mime message. /// </summary> /// <param name="from">Header field From: value.</param> /// <param name="to">Header field To: value.</param> /// <param name="subject">Header field Subject: value.</param> /// <param name="bodyText">Body text of message. NOTE: Pass null is body text isn't wanted.</param> /// <param name="bodyHtml">Body HTML text of message. NOTE: Pass null is body HTML text isn't wanted.</param> /// <returns></returns> public static Mime CreateSimple(AddressList from,AddressList to,string subject,string bodyText,string bodyHtml) { return CreateSimple(from,to,subject,bodyText,bodyHtml,null); }