Browse Source

reply-to missing yet

master
pvincent 3 years ago
parent
commit
c23e3533d8
  1. 18
      src/controller/Messages.hx
  2. 69
      src/sugoi/mail/SendEmailMailer.hx

18
src/controller/Messages.hx

@ -41,11 +41,6 @@ class Messages extends Controller {
var subject = form.getValueOf("subject");
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) {
if (d.email != null)
@ -64,17 +59,8 @@ class Messages extends Controller {
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]);
}
for (x in mails)
e.addRecipient(x);
// sender : default email ( explicitly tells that the server send an email on behalf of the user )
// e.setHeader("Sender", App.config.get("default_email"));

69
src/sugoi/mail/SendEmailMailer.hx

@ -40,53 +40,62 @@ class SendEmailMailer implements IMailer {
return mailer;
}
private function fromString(name:String, email:String) {
return (name == null) ? email : '${name} <${email}>';
}
public function send(e:sugoi.mail.IMail, ?params:Dynamic, ?callback:MailerResult->Void) {
var mailServer = "mail1.zourit.net";
var mailPort = 587;
var to:String;
var bcc:String;
var fromName = "John Doe";
var fromEmail = "no-reply@comptoirduvrac.re";
var recipientCounts = e.getRecipients().length;
if (recipientCounts > 1) {
to = fromString(e.getSender().name, e.getSender().email);
bcc = [for (i in e.getRecipients()) i.email].join(",");
App.log('recipients has been transformed to ${recipientCounts} bcc');
App.log(bcc);
} else {
to = e.getRecipients()[0].email;
bcc = "";
}
var args = [
"-f",
'${fromName} <${fromEmail}>',
// arguments
"-s",
"mail1.zourit.net:587",
'${this.m.host}:${this.m.port}',
"-xu",
${this.m.auth.username},
"-xp",
${this.m.auth.password},
"-o",
"message-charset=utf-8",
"-o",
"message-format=html",
"-o",
"X-Mailer=CagettePei",
"-f",
fromString(e.getSender().name, e.getSender().email),
"-t",
"pvincent@comptoirduvrac.re",
// "-bcc", "pvincent974@gmail.com,pvincent974@laposte.net",
to,
"-bcc",
bcc,
"-u",
e.getSubject(),
"-m",
"alors tout va bien",
"-xu",
"postmaster@comptoirduvrac.re",
"-xp",
"QqQeAPT6EpoK"
'<html>${e.getHtmlBody()}</html>',
];
App.log('args=${args.join(" ")}');
// if (App.config.DEBUG)
// App.log('args=${args.join(" ")}');
var exitCode = Sys.command("sendemail", args);
// var exitCode = 0;
var summary = 'email from="${fromString(e.getSender().name, e.getSender().email)}"> subject=<${e.getSubject()}>';
if (exitCode == 0)
App.log('email from="${e.getSender().name} <${e.getSender().email}"> subject=<${e.getSubject()}> successfully sent');
App.log('$summary successfully sent');
else
App.log('ERROR: email from="${e.getSender().name} <${e.getSender().email}"> subject=<${e.getSubject()}> cannot be sent');
// sys.io.File.saveContent('/tmp/my_file.json', "CONTENT");
// var surprise = m.send({
// subject: e.getSubject(),
// from: new Address({address: e.getSender().email}),
// to: Lambda.array(Lambda.map(e.getRecipients(), function(x) return new Address({address: x.email}))),
// headers: e.getHeaders(),
// content: {
// text: e.getTextBody(),
// html: e.getHtmlBody()
// }
// });
App.log('ERROR: $summary cannot be sent, please review logs');
if (callback != null) {
var map = new MailerResult();

Loading…
Cancel
Save