Description:-
There are more than one way to send emails through Microsoft Dynamics AX system, using X++ code.
(Administration -> Periodic -> E-mail processing -> Email sending status; Form: SysOutgoingEmailTable)
This mechanism based on a system table that contain the emails, and a batch job that scan that table and send the emails, one by one (with retries and status controlling).
This technique is very simple to use and therefore it has some disadvantages; you cannot add attachments or use advanced email properties (cc, bcc, priority flag, etc).
To use this mechanism, first you have to make sure you a SMTP server configured and running.
Go to
Administration -> Setup -> E-mail parameters and fill the required settings:
(Form: SysEmailParameters)
Next step is to make sure the E-mail distributor batch is up and running.
Go to
Basic -> Inquiries -> Batch Job and check if the batch job exists with status Executing orWaiting. (Form: BatchJob)
If it doesn’t, you can activate it from Administration -> Periodic -> E-mail processing -> Batch.
More info:- Configure email functionality in Microsoft Dynamics
Now we are ready to implement our X++ code:
There are more than one way to send emails through Microsoft Dynamics AX system, using X++ code.
(Administration -> Periodic -> E-mail processing -> Email sending status; Form: SysOutgoingEmailTable)
This mechanism based on a system table that contain the emails, and a batch job that scan that table and send the emails, one by one (with retries and status controlling).
This technique is very simple to use and therefore it has some disadvantages; you cannot add attachments or use advanced email properties (cc, bcc, priority flag, etc).
To use this mechanism, first you have to make sure you a SMTP server configured and running.
Go to
Administration -> Setup -> E-mail parameters and fill the required settings:
(Form: SysEmailParameters)
Next step is to make sure the E-mail distributor batch is up and running.
Go to
Basic -> Inquiries -> Batch Job and check if the batch job exists with status Executing orWaiting. (Form: BatchJob)
If it doesn’t, you can activate it from Administration -> Periodic -> E-mail processing -> Batch.
More info:- Configure email functionality in Microsoft Dynamics
Now we are ready to implement our X++ code:
public void POConfirmationEmail(PurchTable _PurchTable) { PurchTable PurchTable; Map parameterMap = new Map(Types::String, Types::String); Email requester; SysEmailId ApprovalEmailTemplate; SysEmailId ReopenEmailTemplate; int itemCount = 1; str ItemId, ItemQty, ItemDeliveryDate, ItemPrice; str companyDetails; FilenameOpen attachmentFilename; companyDetails = curext(); ParameterMap.insert('CompanyDetails',companyDetails); PurchTable = _PurchTable; //attachmentFilename = this.runAndSaveSSRSReport(PurchTable); ParameterMap.insert('VendorName', VendTable::find(PurchTable.OrderAccount).name()); ParameterMap.insert('PurchaseID', PurchTable.PurchId); requester = LogisticsElectronicAddress::findRecId(DirPartyTable::findRec(VendTable::find(PurchTable.OrderAccount).Party).PrimaryContactEmail).Locator; if(!requester) { throw error("No Email address is available"); } else { SysEmailTable::sendMail("PoEmail", companyinfo::languageId(), requester, parameterMap, attachmentFilename); //PoEmail is emial template with two parameter (VendName and PurchId, you can make changes in template as per user requirement. //this.deleteReportFile(attachmentFilename);// To delete this file after email. } }
Thanks for comments.....