Sending emails/notification from D365 FO X++
Suppose there is a scenario where you need to notify someone via email then this approach can be useful to get the appropriate result.
For sending an email we need to configure the environment.
Go to System Administrator> Setup> Email> Email parameters
Fill the form accordingly.
Put your username and password on the respective fields.
While server name and port # are subjective to the SMTP setting of the email. (you can check yours via Email Settings> SMTP Settings)
Now it’s time to trigger the logic so basically, I am creating a runnable class, you can put your logic accordingly.
class RunnableClas
{
????
????public static void main(Args? _args)
????{
???????
???????SysEmailParameters _SysEmailParameters;
?????? ?
var builder = new SysMailerMessageBuilder();
?
?????? select SMTPUserName from _SysEmailParameters;
????????
builder.setFrom(_SysEmailParameters.SMTPUserName);
???????builder.addTo("[email protected]");
???????builder.addTo("[email protected] ");
???????builder.setSubject("For D365 Learning Purpose");
???????builder.setBody("Hello this is Saim Siddiqui");
???????var message = builder.getMessage();
???????SysMailerFactory::getNonInteractiveMailer().sendNonInteractive(message);
???????Info("Email Sent Successfully");
??????
????}
?
}