Skip to content

F2F Email Newsletter Serice

KuersatAydinli edited this page Feb 4, 2018 · 1 revision

Purpose

The email service of the F2F component aims at providing periodical information with respect to the activities in the F2F Central. The newsletter is sent out per end-user subscribed to it. The content of the email is comprised of the feedback of the end-user as well as the feedback provided by the community.

Prerequisites

The email newsletter can only be sent out to end-user whose email information is provided in the Enduser table which has following schema:

id application_id ... username email
1 20 ... test_user test_user@some_provider.com
... ... ... ... ...

Every time the email service is triggered, the end-users are investigated one by one and it is checked whether email information is provided and the end-user reference is not contained in the EmailUnsubscribed table.

Configuration

Set Cronjob

Cronjobs are a flexible way to execute a certain action priodically by pre-defined behaviour. This allows the company, for instance, to send out the newsletter every 2 weeks as well as on every Monday. The newsletter service can be activated at application level once the application is successfully deployed on the server. In order to accomplish this, uncomment following method in the file \src\main\java\fhnw\cere\repository\RepositoryApplication.java:

@Transactional
@PostConstruct
@Scheduled("--> DEFINE CRONJOB HERE<--")
public void sendNewsetter () throws MessagingException, IOException, TemplateException {
emailService.sendNewsletter();
}

The @Scheduled annotation is responsible for triggering the newsletter according to the defined cronjob.

Adjust Email Template

Freemarker framework is leveraged in order to set-up email templates for the newsletter service. This handling facilitates the adjustment of styling as well as content of the emails which are received by the end-users. The base template is located at \src\main\resources\templates\feedback_mail_f2f.ftl. Currently following information models are passed to the template:

  • Enduser
  • List of own feedback entries
  • List of feedback entries from the feedback forum (provided by other end-users) The current email service is set-up by using these infromation elements as parameters. Fortunately, the objects passed to the template easily can be adjusted by modifying following code snippet in the file \src\main\java\ch\fhnw\cere\repository\mail\EmailService.java:
Mail mail = new Mail();
...
Map<String, Object> model = new HashMap<>();
model.put("enduser",user);
model.put("user_feedbacks",userFeedbacks);
model.put("forum_feedbacks",forumFeedbacks);

Adjust Email Interval

The email interval in this section is defined as the time period in days from when the feedback entries will be fetched for being included in the newsletter. For example, if set to 10, then only the feedback from the last 10 days will be considered. It makes sense to set this interval equal to the time interval defined by the cronjob. This way it can be ensured that, for example, running a cronjob every 2 weeks will only include the feedback gathered from the last 2 weeks. The email interval can be set in the properties file located at \src\main\resources\application.properties with the corresponding property key supersede.email.newsletter.day.interval = 14.