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
    Denford
    0

    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 127.0.0.1:25

    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 4123 posts 22194 karma points MVP 9x c-trib
    Aug 12, 2021 @ 13:35
    Matt Brailsford
    100

    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.

    <configuration>
    <system.net>
            <mailSettings>
                <smtp from="[email protected]">
                    <network host="smtp.gmail.com" 
                    port="587" 
                    userName="[email protected]" 
                    password="yourpassword" 
                    enableSsl="true"/>
                </smtp>
            </mailSettings>
    </system.net>
    </configuration>
    

    If you want to use SendGrid you should checkout their docs to see how to use them as a SMTP gateway https://docs.sendgrid.com/for-developers/sending-email/integrating-with-the-smtp-api

    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
    Denford
    0

    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 https://github.com/sendgrid/sendgrid-csharp 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 4123 posts 22194 karma points MVP 9x c-trib
    Aug 16, 2021 @ 08:05
    Matt Brailsford
    0

    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. 👍

    Matt

Please Sign in or register to post replies

Write your reply to:

Draft