Skip to content

Strongly Typed Email Data

Mark McDonald edited this page Mar 18, 2019 · 3 revisions

Not everyone likes using dynamic objects, maybe they like the intellisense too much. Whatever the reason, Postal lets you strongly type your email data if you need to.

Step 1 - Define a class that inherits from Email

namespace App.Models {
  public class ExampleEmail : Email {
    public string To { get; set; }
    public string Message { get; set; }
  }
}

Step 2 - Use that class!

public void Send() {
  var email = new ExampleEmail {
    To = "[email protected]",
    Message = "Strong typed message"
  };
  email.Send();
}

Step 3 - Create a view that uses your model. The name of the view is based on the class name. So ExampleEmail requires a view called "Example.cshtml"

@model App.Models.ExampleEmail
To: @Html.Raw(Model.To)
From: [email protected]
Subject: Example

Hello,
@Model.Message
Thanks!
Clone this wiki locally