Browse Source

App.sendMail

master
pvincent 3 years ago
parent
commit
ed931b7b2c
  1. 1
      .gitignore
  2. 2
      src/App.hx
  3. 48
      src/controller/Messages.hx

1
.gitignore

@ -35,3 +35,4 @@ www/css/*.css
!www/css/bootstrap.min.css !www/css/bootstrap.min.css
config-dev.xml config-dev.xml
config-prod.xml

2
src/App.hx

@ -233,7 +233,7 @@ class App extends sugoi.BaseApp {
var mailer:sugoi.mail.IMailer = new sugoi.mail.BufferedMailer(); var mailer:sugoi.mail.IMailer = new sugoi.mail.BufferedMailer();
if (App.config.DEBUG) { if (App.config.DEBUG) {
// Dev env : emails are written to tmp folder
App.log("DEBUGEmailer enabled => emails are written to tmp folder");
mailer = new sugoi.mail.DebugMailer(); mailer = new sugoi.mail.DebugMailer();
} else { } else {
if (sugoi.db.Variable.get("mailer") == null) { if (sugoi.db.Variable.get("mailer") == null) {

48
src/controller/Messages.hx

@ -38,8 +38,13 @@ class Messages extends Controller {
if (form.checkToken()) { if (form.checkToken()) {
var listId = form.getElement("list").value; var listId = form.getElement("list").value;
var dest = getSelection(listId); var dest = getSelection(listId);
var subject = form.getValueOf("subject");
App.log('about to send emails to listId=<$listId> to destination=${dest.length}');
App.log('about to send email <$subject> to listId=<$listId> to ${dest.length} recipient(s)');
// Sys.command("sh", [
// "-c",
// "sendemail -f no-reply@comptoirduvrac.re -s mail1.zourit.net:587 -t pvincent@comptoirduvrac.re -bcc 'pvincent974@gmail.com, pvincent974@laposte.net' -u TEST -m coucou -xu postmaster@comptoirduvrac.re -xp QqQeAPT6EpoK"
// ]);
var mails = []; var mails = [];
for (d in dest) { for (d in dest) {
@ -51,15 +56,25 @@ class Messages extends Controller {
// send mail confirmation link // send mail confirmation link
var e = new sugoi.mail.Mail(); var e = new sugoi.mail.Mail();
e.setSubject(form.getValueOf("subject"));
for (x in mails)
e.addRecipient(x);
e.setSender(App.config.get("default_email"), form.getValueOf("senderName"));
e.setReplyTo(form.getValueOf("senderMail"), form.getValueOf("senderName"));
App.log('add CC header to message: ${e.getSubject()}');
e.setHeader("CC", "pvincent@comptoirduvrac.re");
e.setSender(App.config.get("default_email"));
e.setSubject(subject);
var replyTo = form.getValueOf("senderMail");
var replyToName = form.getValueOf("senderName");
if (replyTo != null)
e.setReplyTo(replyTo, replyToName);
if (mails.length > 1) {
var cc = mails.join(",");
App.log('add header Cc: $cc');
e.setHeader("CC:", cc);
// for (x in mails)
// e.addRecipient(x);
e.addRecipient(e.getSender().email);
} else {
App.log('no header');
e.addRecipient(mails[0]);
}
// sender : default email ( explicitly tells that the server send an email on behalf of the user ) // sender : default email ( explicitly tells that the server send an email on behalf of the user )
// e.setHeader("Sender", App.config.get("default_email")); // e.setHeader("Sender", App.config.get("default_email"));
@ -67,12 +82,21 @@ class Messages extends Controller {
var html = app.processTemplate("mail/message.mtt", {text: text, group: app.user.amap, list: getListName(listId)}); var html = app.processTemplate("mail/message.mtt", {text: text, group: app.user.amap, list: getListName(listId)});
e.setHtmlBody(html); e.setHtmlBody(html);
App.sendMail(e, app.user.getAmap(), listId, app.user);
// App.sendMail(e, app.user.getAmap(), listId, app.user);
// Sys.command("sendemail", [
// "-f", "no-reply@comptoirduvrac.re", "-s", "mail1.zourit.net:587", "-t", "pvincent@comptoirduvrac.re", "-bcc",
// "pvincent974@gmail.com,pvincent974@laposte.net", "-u", subject, "-m", "alors tout va bien", "-xu", "postmaster@comptoirduvrac.re", "-xp",
// "QqQeAPT6EpoK"
// ]);
sys.io.File.saveContent('/tmp/my_file.json', "CONTENT");
// store message // store message
var lm = new db.Message(); var lm = new db.Message();
lm.amap = app.user.amap; lm.amap = app.user.amap;
lm.recipients = Lambda.array(Lambda.map(e.getRecipients(), function(x) return x.email));
// lm.recipients = Lambda.array(Lambda.map(e.getRecipients(), function(x) return x.email));
lm.recipients = mails;
lm.title = e.getSubject(); lm.title = e.getSubject();
lm.date = Date.now(); lm.date = Date.now();
lm.body = e.getHtmlBody(); lm.body = e.getHtmlBody();

Loading…
Cancel
Save