how to use emailtool class to attach object in email?

Confluence User - 18 Jul, 2022

following code below what properties map to add attachment to email by using plugin.


import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.joget.apps.app.model.AppDefinition;
import org.joget.apps.app.service.AppPluginUtil;
import org.joget.apps.app.service.AppUtil;
import org.joget.plugin.base.ApplicationPlugin;
import org.joget.plugin.base.Plugin;
import org.joget.plugin.base.PluginManager;
import org.joget.plugin.property.model.PropertyEditable;
  
public Object execute(AppDefinition appDef, HttpServletRequest request) {
    String[] emails = new String[]{"email@example.com"};
     
    //Reuse Email Tool to send separated email to a list of users;
    Plugin plugin = pluginManager.getPlugin("org.joget.apps.app.lib.EmailTool");
     
    //Get default properties (SMTP setting) for email tool
    Map propertiesMap = AppPluginUtil.getDefaultProperties(plugin, null, appDef, null);
    propertiesMap.put("pluginManager", pluginManager);
    propertiesMap.put("appDef", appDef);
    propertiesMap.put("request", request);
     
    ApplicationPlugin emailTool = (ApplicationPlugin) plugin;
     
    //send email
    for (String email : emails) {
        propertiesMap.put("toSpecific", email);
        propertiesMap.put("subject", "This is a test email for " + email);
        propertiesMap.put("message", "Email content for " + email+ "");
        propertiesMap.put("Attachments","https://www.orimi.com/pdf-test.pdf");
        
        
        //set properties and execute the tool
        ((PropertyEditable) emailTool).setProperties(propertiesMap);
        emailTool.execute(propertiesMap);
    }
     
    return null;
}
  
//call execute method with injected variable
return execute(appDef, request);

beanshell;emailtools

1


21 Jul, 2022
confluenceUser
confluenceUser

Have you looked into the source code?


EmailTool.java line 129 AppUtil.emailAttachment(properties, wfAssignment, appDef, email);

https://github.com/jogetworkflow/jw-community/blob/7.0-SNAPSHOT/wflow-core/src/main/java/org/joget/apps/app/lib/EmailTool.java#L129 

then look at AppUtil emailAttachment method

https://github.com/jogetworkflow/jw-community/blob/7.0-SNAPSHOT/wflow-core/src/main/java/org/joget/apps/app/service/AppUtil.java#L1214


RELATED QUESTIONS

Your answer


To answer a question you'll need an account.

Print