How to send an email from your application
Puakma supports the easy sending of outbound SMTP mail. To mail enable an Action, all you need is to call the Document's send() method. Calling this method puts the mail in the outbound mail queue to be physically sent by the MAILER server addin task. Following is the basic skeleton for sending an email.
import puakma.system.*;
/**
* Called to send email
*/
public class SendMail extends ActionRunner
{
public String execute()
{
Document doc = new Document(pSystem, pSession.getSessionContext());
doc.replaceItem("From", "info@puakma.net");
doc.replaceItem("Subject", "Important Email");
doc.replaceItem("SendTo", "user1@email.address");
doc.replaceItem("CopyTo", "user2@email.address"); //optional
doc.replaceItem("BlindCopyTo", "user3@email.address"); //optional
doc.replaceItem("Body", "The message goes here and may be HTML format...");
//optional
doc.replaceItem("Importance", "1"); //set as high importance, arrives with a !
doc.replaceItem("ReturnReceipt", "1"); //attach a return receipt
doc.send();
return ""; //return an empty string to denote no redirect
}
}//class
You can easily attach files by creating a new DocumentFileItem(...) on the Document. Each file will be sent as an email attachment.
Multiple recipients are catered for by creating a DocumentMultiItem which may contain multiple recipient values. Use this for the SendTo, CopyTo and BlindCopyTo fields if required.
The call to the send() method returns immediately as the message is queued. Ensure you have a MAILER running against the Puakma database, as this is when the email will be physically transmitted to the recipient's SMTP mail host (see the /puakma/config/puakma.config file for MAILER settings). You can also check the server log in http://your_server/system/admin.pma to see if the mail has been successfully sent.