Skip to content

Sending template emails

Max Strålin edited this page Mar 2, 2019 · 1 revision

Sending an template email is as simple as passing an ITemplateEmailMessage into an IMailjetEmailClient.

Simplest way is using the default implementation, TemplateEmailMessage and MailjetEmailClient, but there's nothing stopping you from passing in any custom ITemplateEmailMessage or using any IMailjetEmailClient.

IMailjetEmailClient mailjetEmailClient = new MailjetEmailClient(opt => /*Configure public/private key*/);
IEmailMessage emailMessage = new TemplateEmailMessage(/*Template Id*/1234, "Sender Name", "Sender Email") {
     To = List<EmailEntity> { new EmailEntity("Recipient name", Recipient email") },
     HtmlBody = @"<div>Here's some HTML</div>"
}
ISendEmailResponse response = mailjetEmailClient.SendAsync(emailMessage);

Note that ITemplateEmailMessage implements IEmailMessage and is therefore accepted by IMailjetEmailClient.SendAsync(IEmailMessage)

Clone this wiki locally