Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Denford 132 posts 323 karma points
    Aug 12, 2021 @ 13:27

    Sending custom Email using TeaCommerce Email templates

    Hi guys,

    Would you be able to point me in the right direction to get this to work e.g. some documentation around how the email templates are set up and work, so basically am trying to use 1 of the built in email templates to manually send a customized email (HTML Wise) after an order is complete.

    Initially just trying to send the email from an order using the confirmation email out of the box, i am getting the error below:

    System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it

    So am thinking there is some configuration of some sort that i need to enable sending these email.

    In my system am currently using Custom logic to send emails using SendGrid, how can i, if possible, use sendgrid to also send the email, assuming i can pretty much use the template i.e. email-template-confirmation.cshtml to customize the HTML i want to be sent in the email.

    Thanks for the help.

  • Matt Brailsford 4124 posts 22220 karma points MVP 9x c-trib
    Aug 12, 2021 @ 13:35
    Matt Brailsford

    Hi Denford,

    That exception suggests it is attempting to send the email, but the server doesn't have an SMTP service configured.

    You'll need to make sure you have SMTP configuration in your web.config, setup with some working details.

                <smtp from="[email protected]">
                    <network host="" 
                    userName="[email protected]" 

    If you want to use SendGrid you should checkout their docs to see how to use them as a SMTP gateway

    In terms of how you send an email, you'll need to use the EmailTemplateService

    var emailTemplate = EmailTemplateService.Instance.Get(storeId, emailTemplateId);
    emailTemplate.Send(model, toEmail);

    This should automatically create the email and send it using the configured SMTP credentials mentioned above.

  • Denford 132 posts 323 karma points
    Aug 15, 2021 @ 13:44

    Thanks for the details will give that a go and let you know how i get on, def didnt have any SMTP setting in my web config as i am using this sendgrid Nuget package which only need the API Key.

    As for sending the email template itself, guess if its from the order page shown below i don't need to use the EmailTemplateService , that will only be if im sending it manually from my own code right?

    enter image description here

  • Matt Brailsford 4124 posts 22220 karma points MVP 9x c-trib
    Aug 16, 2021 @ 08:05
    Matt Brailsford

    Hi Denford,

    Glad that worked for you. And yea, if you are just using the "send email" button, then you don't need to do any custom code. 👍


Please Sign in or register to post replies

Write your reply to: