I'm working on a Module, for which we need a customized version of the new order emails that are sent when an order is placed. What is the proper way to do this for a module? I'm trying to use the Layout Block Argument for template override but I can't seem to get it working for emails.
First create email_templates.xml file in folder Namespace/Modulename/etc.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Email:etc/email_templates.xsd">
<template id="order_template" label="Order template" file="customorder.html" type="html" module="Namespase_Modulename" area="frontend"/>
</config>Now create email template file customorder.html in folder
Namespace/Modulename/view/frontend/email
<!--@subject Email Subject @-->
<!--@vars
{"store url=\"\"":"Store Url",
"skin url=\"images/logo_email.gif\" _area='frontend'":"Email Logo Image"}
@-->
<!--@styles
body,td { color:#2f2f2f; font:11px/1.35em Verdana, Arial, Helvetica, sans-serif; }
@-->
{{template config_path="design/email/header_template"}}
<table cellspacing="0" cellpadding="0" border="0" width="100%">
<tr>
<td align="center" valign="top" style="padding:20px 0 20px 0">
<table bgcolor="#FFFFFF" cellspacing="0" cellpadding="10" border="0" width="650" style="border:1px solid #E0E0E0;">
<tr>
<td valign="top">
<h1 style="font-size:22px;font-weight:normal;line-height:22px;margin:0 0 11px 0;">{{trans "Hello"}},</h1>
</td>
</tr>
<tr>
<td>
<table cellspacing="0" cellpadding="0" border="0" width="650">
<tbody>
<tr>
<td colspan="2" valign="top" style="font-size:12px;padding:7px 9px 9px 9px;border:1px solid #EAEAEA;">
{{var message}}
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td bgcolor="#EAEAEA" align="center" style="background:#EAEAEA;text-align:center;">
<center>
<p style="font-size:12px;margin:0;">
<strong>{{trans "Thank you"}}</strong>
</p>
</center>
</td>
</tr>
</table>
</td>
</tr>
</table>
{{template config_path="design/email/footer_template"}}In the above code, you can set mail subject using <!--@subject Email Subject @-->
You can send a variable value using {{var message}}
Now Call this template from where you want to call it.
Thankyou for that. Now I'm trying to find a way to send out an email programatically, that doesn't depend on some frontend or admin action. Do you know of a way? From what I gather, you can't send an email using the API. I'm trying to send out an email automatically when a certain order status is set.