# How to test the text content of email or SMS Learn how to test the text content of email or SMS with Mailosaur. > [!SUCCESS] > Most email sent today is HTML-based, however, an email will often contain a plain text alternative for older mail clients, which is what this page relates to. Learn how to work with the HTML content of an email. ## Before you begin The examples shown below are based on two key assumptions: 1. You have already created a basic automated test using our [getting started guides](/docs/automation). 2. You have a chosen assertion library that you will use to test the values shown below. ## Accessing the text The text content of an email or SMS message can be accessed via the `text.body` property of a message. ```nodejs console.log(message.text.body) // "Hi Jason, ..." ``` ```python print(message.text.body) # "Hi Jason, ..." ``` ```java System.out.println(message.text().body()); // "Hi Jason, ..." ``` ```csharp Console.WriteLine(message.Text.Body); // "Hi Jason, ..." ``` ```ruby puts(message.text.body) # "Hi Jason, ..." ``` ```php print($message->text->body); // "Hi Jason, ..." ``` ```go fmt.Println(message.Text.Body) // "Hi Jason, ..." ``` ## Working with the content This section describes some of the most common use cases related to the content of an email or SMS message. You should also refer to the guides on working with automatically-extracted content such as [links](/docs/automation/links) and [images](/docs/automation/images). ### Checking if message contains a string ```nodejs const containsText = message.text.body.indexOf('Jason') > -1 console.log(containsText) // true ``` ```python contains_text = "Jason" in message.text.body print(contains_text) # true ``` ```java boolean containsText = message.text().body().contains("Jason"); System.out.println(containsText); // true ``` ```csharp Console.WriteLine(message.Text.Body.Contains("Jason")); // true ``` ```ruby contains_text = message.text.body.include? "Jason" puts(contains_text) # true ``` ```php $containsText = strpos($message->text->body, 'Jason') !== false; print($containsText); // 1 ``` ```go containsText := strings.Contains(message.Text.Body, "Jason") fmt.Println(containsText) // true ``` ### Finding a 6-digit code Note: We recommend using Mailosaur’s [built-in verification code detection](/docs/automation/codes). However, you can also write your own regular expressions to extract values from within your content. The example below shows how to extract a 6-digit numeric code from a message. ```nodejs console.log(message.text.body) // "Your access code is 243546." const regEx = new RegExp('([0-9]{6})') const matches = regEx.exec(message.text.body) console.log(matches[0]) // "243546" ``` ```python print(message.text.body) # "Your access code is 243546." match = re.search("([0-9]{6})", message.text.body) print(match.group()) # "243546" ``` ```java System.out.println(message.text().body()); // "Your access code is 243546." Pattern pattern = Pattern.compile(".*([0-9]{6}).*"); Matcher matcher = pattern.matcher(message.text().body()); matcher.find(); System.out.println(matcher.group(1)); // "243546" ``` ```csharp Console.WriteLine(message.Text.Body); // "Your access code is 243546." var matches = Regex.Matches(message.Text.Body, "([0-9]{6})", RegexOptions.IgnoreCase); Console.WriteLine(matches[0]); // "243546" ``` ```ruby puts(message.text.body) # "Your access code is 243546." match = message.text.body.match(/([0-9]{6})) puts(match[0]) # "243546" ``` ```php print($message->text->body); // "Your access code is 243546." preg_match('/([0-9]){6}/', $message->text->body, $matches); print($matches[0]); // "243546" ``` ```go fmt.Println(message.Text.Body) // "Your access code is 243546." r, _ := regexp.Compile("([0-9]{6})") fmt.Println(r.FindString(message.Text.Body)) // "243546" ``` ### Finding an 8-digit alphanumeric code In this example, an 8-digit code, consisting of 2 letters, followed by 6 numbers is extracted. ```nodejs console.log(message.text.body) // "Your access code is QZ524822." const regEx = new RegExp('([A-Z]{2}[0-9]{6})') const matches = regEx.exec(message.text.body) console.log(matches[0]) // "Q2ZH482S" ``` ```python print(message.text.body) # "Your access code is QZ524822." match = re.search("([A-Z]{2}[0-9]{6})", message.text.body) print(match.group()) # "Q2ZH482S" ``` ```java System.out.println(message.text().body()); // "Your access code is QZ524822." Pattern pattern = Pattern.compile(".*([A-Z]{2}[0-9]{6}).*"); Matcher matcher = pattern.matcher(message.text().body()); matcher.find(); System.out.println(matcher.group(1)); // "Q2ZH482S" ``` ```csharp Console.WriteLine(message.Text.Body); // "Your access code is QZ524822." var matches = Regex.Matches(message.Text.Body, "([A-Z]{2}[0-9]{6})", RegexOptions.IgnoreCase); Console.WriteLine(matches[0]); // "Q2ZH482S" ``` ```ruby puts(message.text.body) # "Your access code is QZ524822." match = message.text.body.match(/([A-Z]{2}[0-9]{6})) puts(match[0]) # "Q2ZH482S" ``` ```php print($message->text->body); // "Your access code is QZ524822." preg_match('/([0-9]){6}/', $message->text->body, $matches); print($matches[0]); // "Q2ZH482S" ``` ```go fmt.Println(message.Text.Body) // "Your access code is QZ524822." r, _ := regexp.Compile("([A-Z]{2}[0-9]{6})") fmt.Println(r.FindString(message.Text.Body)) // "Q2ZH482S" ```