-
New Feature
-
Resolution: Duplicate
-
Major
-
4.3.0
-
None
-
4.3 RC2
<?xml version="1.0" encoding="UTF-8"?> <function class="org.ametys.plugins.core.ui.script.StaticConfigurableScriptBinding"> <descriptions> <description> <name>SendMail.asText</name> <text i18n="true">PLUGINS_RUNTIME_SCRIPT_FCT_SEND_MAIL_AS_TEXT</text> </description> <description> <name>SendMail.asHTML</name> <text i18n="true">PLUGINS_RUNTIME_SCRIPT_FCT_SEND_MAIL_AS_HTML</text> </description> </descriptions> <script> var SendMail = (function() { // Imports var Config = Java.type("org.ametys.runtime.config.Config"); var SendMailHelper = Java.type("org.ametys.core.util.mail.SendMailHelper"); var SimpleDateFormat = Java.type("java.text.SimpleDateFormat"); var DateUtil = Java.type("java.util.Date"); var Arrays = Java.type("java.util.Arrays"); // Variables var SENDER = Config.getInstance().getValue("smtp.mail.from"); var dateFormat = new SimpleDateFormat("dd/MM/yyyy"); var current = new DateUtil(); function asHTML(subject, body, recipients) { _send(subject, body, null, recipients); } function asText(subject, body, recipients) { _send(subject, null, body, recipients); } function _send(subject, bodyAsHTML, bodyAsText, recipients) { var subjectPrefix = "[Script - " + dateFormat.format(current) + "] "; var recipientsAsList = _jsArrayToJavaList(recipients); SendMailHelper.sendMail(subjectPrefix + subject, bodyAsHTML, bodyAsText, recipientsAsList, SENDER); } function _jsArrayToJavaList(array) { return Arrays.asList(array); } return { asHTML: asHTML, asText: asText }; })(); </script> </function>
Here are i18n keys (french version only):
<message key="PLUGINS_RUNTIME_SCRIPT_FCT_SEND_MAIL_AS_TEXT">envoi d'un mail au format texte à la liste de destinataires donnée (ex: <i>SendMail.asText("Sujet du mail", "Corps du mail", ["destinataire1@mail.org", "destinataire2@mail.org"])</i>)</message> <message key="PLUGINS_RUNTIME_SCRIPT_FCT_SEND_MAIL_AS_HTML">envoi d'un mail au format HTML à la liste de destinataires donnée (ex: <i>SendMail.asHTML("Sujet du mail", "Corps du mail", ["destinataire1@mail.org", "destinataire2@mail.org"])</i>)</message>
Use it as :
SendMail.asText("test sujet", "test corps", ["mymail@mail.org", "mysecondmail@mail.org"]); SendMail.asHTML("test sujet", "<span style='color:red'>test corps rouge</span>", ["mymail@mail.org"]);
- Duplique
-
RUNTIME-3318 Add new script to send mail
- Closed
- Référence
-
RUNTIME-3018 See console script resuls after a timeout
- Closed