Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Emails and SMS

There are essentially four ways to send email messages:

  1. Sending to a single object instance that implements the Identity interface. The Mezzanine ID e-mail address associated with the Identity will automatically be used.
  2. Sending to an arbitrary e-mail address

An example for sending outgoing SMS is also included below.

 

Status
colourBlue
titleHEADS UP
 Note that it is possible to send emails, with optional attachments. Html tags (<table>,<br>,<h2>,<b>,...) can be used to format text.

 

Info
  1. @Role(“Doctor”)
  2. persistent object Doctor{
  3. }
  4.  
  5. persistent object Patient {
  6.     string emailAddress;
  7. }
  8.  
  9. void mailToIdentity(Doctor d){
  10.     Mez:email(d, "email.descriptionKey", "email.subjectKey", "email.bodyKey");
  11. }
  12.  
  13. void mailToAddress(Patient p){
  14.     Mez:email(p.emailAddress, "email.descriptionKey", "email.subjectKey", "email.bodyKey");
  15. }
  16.  
  17. void mailAttachments(Doctor d){
  18.    Mez:email(d, "email.descriptionKey", "email.subjectKey", "/jasper/report1/master.jxrml");
  19. }
  20.  
  21. void sendSms() {
  22.    Client client = Client:new();
  23.    client.mobileNumber = "27730085850";
  24.    Mez:sms(client, "mobileNumber", "exampleKey.smsText");
  25. }

 Additionally if more flexible naming is required for the emailed reports, there exists an additional syntax that specifies a "naming" function. This function is a 0-arg function that returns a string that will be run when the report is generated/emailed. A function can be specified for each report, or the same function can be specified multiple times. A single report "pair" can be specified or multiple.

Code Block
languagebash
linenumberstrue
string myNamingFunctionTwo() {
	return "Trainee_Workout_Report_No_Two";
}
string myNamingFunction() {
	return "Trainee_Workout_Report_No_One";
}
void mailWorkouts() {
	Trainee uTrainee = Trainee:user();
	string traineeFname = uTrainee.fname;
	string traineeSname = uTrainee.sname;
	string traineeUUID = uTrainee._id;
	Mez:emailAttach(uTrainee.email, "email_desc.trainee_workouts_report", "email_subject.trainee_workouts_report", "email_body.trainee_workouts_report", {"trainee-workouts-report/trainee_workouts_report.jrxml", myNamingFunction()}, {"trainee-workouts-report/trainee_workouts_report_two.jrxml", myNamingFunctionTwo()});
} 

Specifying Custom E-mail Templates

To change the layout, images or colours of the e-mail for e.g. custom branding purposes, a final enum parameter can be added to the Mez:email or Mez:emailAttach BIFs to specify a custom (html) e-mail template. The enumerated type is EMAIL_TEMPLATES, with the specified enum member the html file name (without the extension), as included by the developer under the web-app/email-templates directory. Images for this template is to be included under web-app/images, and prefixed by "cid" in the html.

Code Block
languagejava
titleDSL snippet
Mez:email(emailAddress, "input.email_subject_static", "input.email_subject_static", "input.email_body_static", EMAIL_TEMPLATES.myEmailTemplate);
Code Block
languagexml
titleweb-app/email-templates/myEmailTemplate.html snippet
<img alt="logo" width="190" height="61" src="cid:myCustomLogo.png" />

Please note that it is not mandatory to have the email-template folder. If one is not included the original default email template in service will be used to send messages. 

To override this behaviour you can include just one template called "default.html" which will then be used for all the mails instead of the original "default" template. Just including the file will enable the behaviour without you having to explicitly mention the template when the email syntax is used. More customization will require you to indicate the template you want to use via above mentioned enumeration. 

No Format
└── web-app
    ├── email-templates
    │   └── myEmailTemplate.html
    └── images
        └── myCustomLogo.png

Please refer to the default e-mail template as an example or starting point for your custom template: email_template.html. Note that it contains ${subject}, ${body} and ${applicationInstanceName} placeholders that are replaced at runtime. In essence these placeholders should always be standard and included in any variation of custom template you introduce.