Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon Can I use HTML templates for email composition in MvvmCross


Can I use HTML templates for email composition in MvvmCross


Using HTML Templates for Email Composition in MvvmCross

MvvmCross provides a plugin for sending emails, but it does not directly support using HTML templates for email composition. However, you can still use HTML in your email content by setting the `isHtml` parameter to `true` when composing an email using the `IMvxComposeEmailTask` interface.

Composing Emails with HTML Content

To send an email with HTML content in MvvmCross, you can use the following approach:

csharp
var emailTask = Mvx.IoCProvider.Resolve();
emailTask.ComposeEmail(
    "
 <script language='JavaScript' type='text/javascript'>
 <!--
 var prefix = 'm&#97;&#105;lt&#111;:';
 var suffix = '';
 var attribs = '';
 var path = 'hr' + 'ef' + '=';
 var addy17890 = 'r&#101;c&#105;p&#105;&#101;nt' + '&#64;';
 addy17890 = addy17890 + '&#101;x&#97;mpl&#101;' + '&#46;' + 'c&#111;m';
 document.write( '<a ' + path + '\'' + prefix + addy17890 + suffix + '\'' + attribs + '>' );
 document.write( addy17890 );
 document.write( '<\/a>' );
 //-->
 </script><script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '<span style=\'display: none;\'>' );
 //-->
 </script>This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 <script language='JavaScript' type='text/javascript'>
 <!--
 document.write( '</' );
 document.write( 'span>' );
 //-->
 </script>",
    string.Empty,
    "Email Subject",
    "This is an HTML email.",
    true);

In this example, the `isHtml` parameter is set to `true`, indicating that the email body contains HTML content.

Creating HTML Email Templates

While MvvmCross does not provide built-in support for HTML email templates, you can create your own templates using standard HTML and CSS. However, keep in mind the limitations of email clients when it comes to rendering HTML and CSS:

- Use Inline Styles: Email clients often do not support external stylesheets, so use inline styles within your HTML tags.
- Keep CSS Simple: Stick to basic CSS properties like font size, color, and background color. Avoid complex features like shadows or animations.
- Test Across Clients: Use tools like Litmus or Email on Acid to ensure your emails display correctly across different email clients.

Tools for Creating HTML Email Templates

If you need to create more complex HTML email templates, consider using external tools or frameworks:

- MJML: A markup language specifically designed for creating responsive emails that work well across most email clients.
- Email Template Builders: Tools like Postcards or Beefree allow you to create and edit email templates without extensive coding knowledge.

Conclusion

While MvvmCross does not directly support using HTML templates for email composition, you can still send emails with HTML content by setting the appropriate flag. For more complex templates, consider using external tools or frameworks designed for email development.

Citations:
[1] https://www.mvvmcross.com/documentation/plugins/email
[2] https://community.veracross.com/s/article/Template-Formatting-for-System-Emails
[3] https://stackoverflow.com/questions/60190481/should-html-email-template-use-table-element-for-the-layout
[4] https://www.reddit.com/r/Frontend/comments/zkg2wy/how_am_i_supposed_to_create_html_emails/
[5] https://github.com/jimbobbennett/MvvmCross-Templates
[6] https://designmodo.com/html-css-emails/
[7] https://beefree.io/blog/the-ultimate-guide-to-creating-and-embedding-html-email-templates-in-outlook
[8] https://github.com/jimbobbennett/MvvmCross-VisualStudioAddIn
[9] https://salesforce.stackexchange.com/questions/180980/how-to-send-an-email-template-via-apex
[10] https://www.emailonacid.com/blog/article/email-development/email-development-best-practices-2/