Friday, December 1, 2023

Send email X++

public static void sendEmail(str _fileName,
                                 str _subject,
                                 str _body,
                                 System.IO.MemoryStream _memoryStream,
                                 Email _fromEmail, 
                                 Email _toEmail)
    {
        SysMailerMessageBuilder mailer = new SysMailerMessageBuilder();
        try
        {
            mailer.setSubject(_subject);

            //mailer.setFrom(_fromEmail);

            mailer.setBody(_body);

            mailer.addTo(_toEmail);

            mailer.addAttachment(_memoryStream, _fileName);

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

            Info("@SYS58551");
        }
        catch (Exception::CLRError)
        {
            System.Exception ex = ClrInterop::getLastException();
            if (ex != null)
            {
                ex = ex.get_InnerException();
                if (ex != null)
                {
                    error(ex.ToString());
                }
            }
        }
        catch (Exception::Error)
        {
            Error("@ErrorOccurredFailedSendEmail");
        }
    }

No comments:

Post a Comment

Table browser URL in D365FO

Critical Thinking icon icon by Icons8