# Message properties Learn how to test the common properties of an email or SMS message with Mailosaur. ## 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. ## Email subject Allows you to check that the correct subject will be displayed in a recipient’s mail client. ```nodejs console.log(message.subject) // "Hello world" ``` ```python print(message.subject) # "Hello world" ``` ```java System.out.println(message.subject()); // "Hello world" ``` ```csharp Console.WriteLine(message.Subject); // "Hello world" ``` ```ruby puts(message.subject) # "Hello world" ``` ```php print($message->subject); // "Hello world" ``` ```go fmt.Println(message.Subject) // "Hello world" ``` ## Recipients The `to` property of a message contains an array of all recipients of a message (excluding those that have been carbon-copied on an email). ```nodejs console.log(message.to[0].name) // "Jill Smith" console.log(message.to[0].email) // "jill@example.com" // Phone number (for SMS tests only) console.log(message.to[0].phone) // "+15554532452" ``` ```python print(message.to[0].name) # "Jill Smith" print(message.to[0].email) # "jill@example.com" # Phone number (for SMS tests only) print(message.to[0].phone) # "+15554532452" ``` ```java System.out.println(message.to().get(0).name()); // "Jill Smith" System.out.println(message.to().get(0).email()); // "jill@example.com" // Phone number (for SMS tests only) System.out.println(message.to().get(0).phone()); // "+15554532452" ``` ```csharp Console.WriteLine(message.To[0].Name); // "Jill Smith" Console.WriteLine(message.To[0].Email); // "jill@example.com" // Phone number (for SMS tests only) Console.WriteLine(message.To[0].Phone); // "+15554532452" ``` ```ruby puts(message.to[0].name) # "Jill Smith" puts(message.to[0].email) # "jill@example.com" # Phone number (for SMS tests only) puts(message.to[0].phone) # "+15554532452" ``` ```php print($message->to[0]->name); # "Jill Smith" print($message->to[0]->email); # "jill@example.com" // Phone number (for SMS tests only) print($message->to[0]->phone); # "+15554532452" ``` ```go fmt.Println(message.To[0].Name) // "Jill Smith" fmt.Println(message.To[0].Email) // "jill@example.com" // Phone number (for SMS tests only) fmt.Println(message.To[0].Phone) // "+15554532452" ``` ### Carbon copy (CC) recipients ```nodejs console.log(message.cc[0].name) // "Jack Smith" console.log(message.cc[0].email) // "jack@example.com" ``` ```python print(message.cc[0].name) # "Jack Smith" print(message.cc[0].email) # "jack@example.com" ``` ```java System.out.println(message.cc().get(0).name()); // "Jack Smith" System.out.println(message.cc().get(0).email()); // "jack@example.com" ``` ```csharp Console.WriteLine(message.Cc[0].Name); // "Jack Smith" Console.WriteLine(message.Cc[0].Email); // "jack@example.com" ``` ```ruby puts(message.cc[0].name) # "Jack Smith" puts(message.cc[0].email) # "jack@example.com" ``` ```php print($message->cc[0]->name); # "Jack Smith" print($message->cc[0]->email); # "jack@example.com" ``` ```go fmt.Println(message.Cc[0].Name) // "Jack Smith" fmt.Println(message.Cc[0].Email) // "jack@example.com" ``` ### Blind carbon-copy (BCC) recipients ```nodejs console.log(message.bcc[0].name) // "Bob Smith" console.log(message.bcc[0].email) // "bob@example.com" ``` ```python print(message.bcc[0].name) # "Bob Smith" print(message.bcc[0].email) # "bob@example.com" ``` ```java System.out.println(message.bcc().get(0).name()); // "Bob Smith" System.out.println(message.bcc().get(0).email()); // "bob@example.com" ``` ```csharp Console.WriteLine(message.Bcc[0].Name); // "Bob Smith" Console.WriteLine(message.Bcc[0].Email); // "bob@example.com" ``` ```ruby puts(message.bcc[0].name) # "Bob Smith" puts(message.bcc[0].email) # "bob@example.com" ``` ```php print($message->cc[0]->name); # "Bob Smith" print($message->cc[0]->email); # "bob@example.com" ``` ```go fmt.Println(message.Bcc[0].Name) // "Bob Smith" fmt.Println(message.Bcc[0].Email) // "bob@example.com" ``` ## Sender The `from` property of a message contains an array of senders. In almost all cases there will only be 1, however, the email specification technically allows for multiple senders to exist. ```nodejs console.log(message.from[0].name) // "Customer Support" console.log(message.from[0].email) // "noreply@example.com" // Phone number (for SMS tests only) console.log(message.from[0].phone) // "+15554532452" ``` ```python print(message.sender[0].name) # "Customer Support" print(message.sender[0].email) # "noreply@example.com" # Phone number (for SMS tests only) print(message.sender[0].phone) # "+15554532452" ``` ```java System.out.println(message.from().get(0).name()); // "Customer Support" System.out.println(message.from().get(0).email()); // "noreply@example.com" // Phone number (for SMS tests only) System.out.println(message.from().get(0).phone()); // "+15554532452" ``` ```csharp Console.WriteLine(message.From[0].Name); // "Customer Support" Console.WriteLine(message.From[0].Email); // "noreply@example.com" // Phone number (for SMS tests only) Console.WriteLine(message.From[0].Phone); // "+15554532452" ``` ```ruby puts(message.from[0].name) # "Customer Support" puts(message.from[0].email) # "noreply@example.com" # Phone number (for SMS tests only) puts(message.from[0].phone) # "+15554532452" ``` ```php print($message->from[0]->name); # "Customer Support" print($message->from[0]->email); # "noreply@example.com" // Phone number (for SMS tests only) print($message->from[0]->phone); # "+15554532452" ``` ```go fmt.Println(message.From[0].Name) // "Customer Support" fmt.Println(message.From[0].Email) // "noreply@example.com" // Phone number (for SMS tests only) fmt.Println(message.From[0].Phone) // "+15554532452" ``` ## Email Headers Emails contain a set of headers that are used to transmit metadata which is typically not visible to the recipient. All email headers are available via the `metadata.headers` property of a message. Each header has both a `field` and `value` property. ```nodejs const headers = message.metadata.headers const returnPath = headers.find( h => h.field.toLowerCase() === 'return-path' ) console.log(returnPath.value); // "" ``` ```python headers = message.metadata.headers return_path = [h for h in headers if h.field.lower() == "return-path"] print(return_path[0].value) # "" ``` ```java List headers = message.metadata().headers(); Optional returnPath = headers.stream() .filter(h -> h.field().toLowerCase().equals("return-path")).findFirst(); System.out.println(returnPath.get().value()); // "" ``` ```csharp var headers = message.Metadata.Headers; var returnPath = headers.First(h => h.Field.ToLowerInvariant().Equals("return-path")); Console.WriteLine(returnPath.Value); // "" ``` ```ruby headers = message.metadata.headers idx = headers.find_index{ |h| h.field.downcase == "return-path" } puts(headers[idx].value) # "" ``` ```php $headers = $message->metadata->headers; $returnPath = array_values(array_filter($headers, function ($h) { return strtolower($h->field) === "return-path"; }))[0]; print($returnPath->value); ``` ```go headers := message.Metadata.Headers idx := sort.Search(len(headers), func(i int) bool { return strings.ToLower(headers[i].Field) == "return-path" }) fmt.Println(headers[idx].Value) // "" ```