diff --git a/.gitignore b/.gitignore index 8e8e1f4..4b91e19 100755 --- a/.gitignore +++ b/.gitignore @@ -35,3 +35,4 @@ www/css/*.css !www/css/bootstrap.min.css config-dev.xml +config-prod.xml diff --git a/src/App.hx b/src/App.hx index 24fb6f8..bb60cf0 100755 --- a/src/App.hx +++ b/src/App.hx @@ -233,7 +233,7 @@ class App extends sugoi.BaseApp { var mailer:sugoi.mail.IMailer = new sugoi.mail.BufferedMailer(); 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(); } else { if (sugoi.db.Variable.get("mailer") == null) { diff --git a/src/controller/Messages.hx b/src/controller/Messages.hx index 8d3ba56..fbe4f3d 100755 --- a/src/controller/Messages.hx +++ b/src/controller/Messages.hx @@ -38,8 +38,13 @@ class Messages extends Controller { if (form.checkToken()) { var listId = form.getElement("list").value; 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 = []; for (d in dest) { @@ -51,15 +56,25 @@ class Messages extends Controller { // send mail confirmation link 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 ) // 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)}); 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 var lm = new db.Message(); 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.date = Date.now(); lm.body = e.getHtmlBody();