Monday, July 8, 2024

Send email with report attachment in D365 F&O

  public static void sendEmail(System.IO.MemoryStream   _mstream, Filename    _fileName, str _requestID)

    {

        Map                                     templateTokens;

        str                                     emailSubject,emailBody;

        Filename                                fileName;

        SysEmailTable                           SysEmailTable;

        var messageBuilder      = new SysMailerMessageBuilder();

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

        select SysEmailTable;

        emailSubject = "Vendor Request Report";

        templateTokens.insert("@SYS74341", emailSubject);

        templateTokens.insert("@SYS4009003", _fileName);

        emailBody =  strFmt("A vendor request has been registed with the vendor request id %1 please find the attached document for more information.",_requestID);

        emailBody = SysEmailMessage::stringExpand(emailBody, SysEmailTable::htmlEncodeParameters(templateTokens));

        emailBody = strReplace(emailBody, '\n', '<br>');

        emailBody +='<br><br>Thanks,<br>' +'Daxarch'; // for thanks

        messageBuilder.addTo("lohith.m@daxarch.in")

                                    .setSubject(emailSubject)

                                    .setBody(emailBody)

                                    .addCC("");


        messageBuilder.setFrom("lohithmudigonda.m@gmail.com" , "Thiru") ; //sendor mail must be configured in front end.

        messageBuilder.addAttachment(_mstream, _fileName);


        SysMailerFactory::sendNonInteractive(messageBuilder.getMessage());


        info(strFmt("Email sent successfully for vendor request %1",_requestID));

    }

............................

Configure the sendor mail id :




Output :




No comments:

Post a Comment