How to send an email from an Extension

Emails can be sent directly from your server side code in order to provide registration confirmations, updates or even debugging and stats reports.

In order to enable email sending you will need to setup the Emailer Service from the AdminTool: from theServerConfigurator choose the Emailer tab, turn on the service and set your SMTP parameters.

Restart the server and you are now ready to send emails using a couple of lines of code like this:

Email myEmail = new SFSEmail("sender@email.com", "recipient@email.it", "Test mail", "Hello from SFS2X");
SmartFoxServer.getInstance().getMailService().sendEmail(myEmail);

There are three modalities to send emails: “blindly”, with a confirmation event and delayed. You can learn about this and lots more from the SFSPostOffice class in the javadoc.