MimeKit.MimeMessage.GetTextBody C# (CSharp) Method

GetTextBody() public method

Gets the text body in the specified format.
Gets the text body in the specified format, if it exists.
public GetTextBody ( TextFormat format ) : string
format TextFormat The desired text format.
return string
		public string GetTextBody (TextFormat format)
		{
			var multipart = Body as Multipart;

			if (multipart != null) {
				string text;

				if (TryGetMultipartBody (multipart, format, out text))
					return text;
			} else {
				var body = Body as TextPart;

				if (body != null && body.IsFormat (format))
					return body.Text;
			}

			return null;
		}

Usage Example

Example #1
0
 public Message(MimeMessage inMessage)
 {
     MessageId = inMessage.MessageId;
     From = inMessage.From.InternetAddressListToDictionary();
     Cc = inMessage.Cc.InternetAddressListToDictionary();
     Bcc = inMessage.Bcc.InternetAddressListToDictionary();
     Date = inMessage.Date;
     Subject = inMessage.Subject;
     MessageText = inMessage.GetTextBody(TextFormat.Text);
     if (string.IsNullOrEmpty(MessageText))
     {
         try
         {
             MessageText = HtmlToText.ConvertHtml(inMessage.HtmlBody).Replace("\r", "").Replace("\n", "");
         } catch(Exception ex)
         {
             MessageText = "-";
         }
     }
 }
All Usage Examples Of MimeKit.MimeMessage::GetTextBody