

Below is the complete code of the EmailController. Simply pass that HTML as your email body. After that write the Mjml syntax for your email template and call the “Render” method of the Mjml service. Inject “MjmlServices” through the constructor and create a HttpGet method by the name “Send” which returns Ok in case of successful email send. We have successfully created the Mjml service now it’s time to inject it into our controller. For this purpose, write the below code in your “ConfigureServices” method in the startup.cs class and also add namespace “using Mjml.AspNetCore”. You can use dependency injection which will make it much easier to use Mjml Services.
#Send email mjml visual studio code install#
Write MJML in the browse tab and install the latest stable version of Mjml.AspNetCore package.Īfter installing the package add the namespace of “using Mjml.AspNetCore” in EmailController. After creating the EmailController right-click on your project and click on manage NuGet packages. Name the controller as “EmailController”. Right-click on the Controller folder and add a new empty MVC Controller. There will be a few folders and files in the project already. It will take few seconds and your project will be created. Select target framework as 3.1 and click on Create. Stepsįirst of all open visual studio and click on create a new project. There are several ways where you can choose from. As no e-mail client can parse MJML directly, you have to generate the HTML code before sending the e-mails to the recipients. (we will use MJML Framework as this plugin for Visual Studio Code). Some e-mail clients like Outlook doesn’t use width styles for images and for those, you should add a width attribute to the img tag directly. We will simply pass it to our email body and it will be rendered in our email. You need to pay attention to building and implementing responsive emails which isnt. Then we will write the MJML syntax for our email template and then we will call the “Render” method of the MJML Service which returns the HTML. The only thing we do in our API is to add the NuGet package of MJML. The abstraction it offers ensures you stay up-to-date with industry practice and responsiveness. MJML is designed with responsiveness in mind. Creating a responsive email is much easier with tags like, , and. Say get rid of the endless HTML table or email client email. Make your speed and productivity enhanced with MJML semantic syntax. MJML sums up everything Mailjet has learned about HTML email creation over the past few years and includes a whole layer of complexity related to responsive email creation.
#Send email mjml visual studio code how to#
In this article, you will learn how to integrate Mailjet Markup Language (MJML) in your ASP.
