Showing posts with label SMTP. Show all posts
Showing posts with label SMTP. Show all posts

Monday, April 20, 2026

Stop sending notifications from dynamics through SMTP when you have subject #FAIL#

Scenario :- I got a requirement where dynamics sends notification and these notifications are to be restricted so these the logic where you can control the notifications.

Code:-

ExtensionOf(classstr(SysMailerSMTP))]
 final class NotificationsstopSysMailerSMTP_Extension
{

    protected boolean sendMessage(System.Net.Mail.MailMessage _message, boolean _interactive, guid _correlationId)
    {
        str val="#FAIL#";
        if(strKeep(val,_message.Subject)==val)
        {
            System.Net.Mail.MailAddress buf;
            System.Net.Mail.MailAddressCollection buf2;
            System.Net.Mail.MailMessage _messageloc;
            _message=_messageloc;
            _message.Subject='';
            _message.Sender=buf;
        }
        boolean ret;
       
        ret =  next sendMessage( _message,  _interactive,  _correlationId);
        return ret;
       
    }

}

NOTE:- This is a framework class customizations .So make sure we go with procedure  until and unless you are confident to implement the change

Thank you !! 

Sunday, February 15, 2026

Send mail Through SMTP with Template

 In this blog we see how to send mail through SMTP by using template 

Step 1:-

  Code :-

  Map           templateTokens;

  templateTokens = new Map(Types::String, Types::String);     

   SysMailerSMTP           mailer = new SysMailerSMTP();

        try

        {

            switch (workflowContext.parmTableId())

            {

                case tablenum(LedgerJournaltable) :

                    SysMailerMessageBuilder builder = new SysMailerMessageBuilder(); 

                

                    SysEmailParameters      parameters = SysEmailParameters::find();

 

                    SysEmailMessageSystemTable  messageTable;

                    str envUrl = URLUtility::getUrl();

                    select messageTable

            where messageTable.EmailId == "Template name";


              

                    templateTokens.insert("envUrl",envUrl);

                    templateTokens.insert("Ledger journal table.JournalName",strFmt("%1",ledgerJournaltable.JournalName));  


                    if (parameters.SMTPRelayServerName)

                    {

                        mailer.smtpRelayServer(parameters.SMTPRelayServerName,


                                        parameters.SMTPPortNumber,


                                        parameters.SMTPUserName,


                                        SysEmailParameters::password(),


                                        parameters.SMTPUseNTLM,parameters.SMTPRequireSSL);

                    }

                    else

                    {

                        warning("ServerNotFound");

                    }

                    if (messageTable.EmailId)

                    {

                        builder.setFrom(parameters.SMTPUserName);

                        

                            builder.addTo(conPeek(con, i)).setSubject(strFmt("%1",messageTable.Subject + ledgerJournaltable.JournalNum)).setBody(SysEmailMessage::stringExpand(messageTable.Mail, SysEmailTable::htmlEncodeParameters(templateTokens)));

                         

                        SysMailerFactory::getNonInteractiveMailer().sendNonInteractive(builder.getMessage());

                        info('Mail successfully sent');

                    }

        }

     }

        catch (Exception::Error)

        {

            throw error("@SYS326780");

        }

    }

Step 2:-Configure template name in frontend 

Path:-

System administration > Setup > Email > System email templates

 


Thank you!!
Note:-Don't forget to configure SMTP details in front end and make sure done with Test connection

Undo settlement of payment and invoice through code

 internal final class RunnableClasstestforundosettlement {     /// <summary>     /// Class entry point. The system will call this meth...