|
|
@ -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(); |
|
|
|