Skip to content
Other versions

Loading…

MailUtils

Utility methods to send mail. For example, to send a message or send a document. 

Description:

Method Return values Description
sendMessage(String toAddress, String subject, String content) void Send mail without a FROM address.
  • toAddress: The destination addresses for mail.
  • subject: The mail subject.
  • content: The mail body.

Example:

package com.openkm;
import com.openkm.util.ContextWrapper;
import com.openkm.util.MailUtils;
public class Test {
public static void main(String[] args) {
try {
MailUtils mailUtils = ContextWrapper.getContext().getBean(MailUtils.class);
mailUtils.sendMessage("noreply@openkm.com", "this is the subject", "This is the text");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
sendMessage(String fromAddress, String toAddress, String subject, String content) void Send mail with a FROM address.
  • fromAddress: The from address for mail.
  • toAddress: The destination addresses for mail.
  • subject: The mail subject.
  • content: The mail body.

Example:

package com.openkm;
import com.openkm.util.ContextWrapper;
import com.openkm.util.MailUtils;
public class Test {
public static void main(String[] args) {
try {
MailUtils mailUtils = ContextWrapper.getContext().getBean(MailUtils.class);
mailUtils.sendMessage("from_noreply@openkm.com", "to_noreply@openkm.com", "this is the subject", "This is the text");
} catch (Exception e) {
e.printStackTrace();
}
}
}

Description:

Method Return values Description
sendDocuments(String fromAddress, List toAddresses, String subject, String text, List docsPath) MimeMessage Send documents to non-registered OpenKM users.
  • fromAddress: The from address for mail.
  • toAddress: The list of destination addresses for mail.
  • subject: The mail subject.
  • text: The mail body.
  • docsPath: The path of the documents to be sent.

Example:

package com.openkm;
import java.util.ArrayList;
import java.util.List;
import com.openkm.util.ContextWrapper;
import com.openkm.util.MailUtils;
public class Test {
public static void main(String[] args) {
try {
MailUtils mailUtils = ContextWrapper.getContext().getBean(MailUtils.class);
List<String> docsPath = new ArrayList<>();
List<String> listAddress = new ArrayList<>();
listAddress.add("to_noreply@openkm.com");
docsPath.add("/home/openkm/test.png");
docsPath.add("/home/openkm/test2.png");
docsPath.add("/home/openkm/test3.png");
mailUtils.sendDocuments("from_noreply@openkm.com", listAddress, "this is the subject", "This is the text",
docsPath);
} catch (Exception e) {
e.printStackTrace();
}
}
}