examples icon indicating copy to clipboard operation
examples copied to clipboard

Can't set dynamic from/replyTo

Open trsh opened this issue 9 years ago • 4 comments

CHANGELOG: we have replaced [replyTo] argument for [language] argument.

Why?

trsh avatar Jun 30 '17 08:06 trsh

Since controller.mail returns instance of MailMessage https://docs.totaljs.com/latest/en.html#api~FrameworkMail You can do following:

var message = controller.mail(...);
message.to(...);
message.reply(...);

It's all in the docs https://docs.totaljs.com

molda avatar Jun 30 '17 09:06 molda

@molda but the function executes sending it self. So the parametrs will be set after sending happened? Or sending is done after controller function is done?

trsh avatar Jun 30 '17 10:06 trsh

Hi @trsh, email is sent in the next tick. For understanding:

var message = controller.mail(...);

// This hidden code will be executed in the next tick
setImmediate(function() {
   message.send();
});

// Your code:
message.to('...');
message.replay('...');

Why language? Because framework can localize subject and body automatically and this change was the only way how to do it.

var msg = controller.mail('[email protected]', '@(This subject will be localized with the view automatically)', 'view_name', model, model.language || '');
msg.reply('[email protected]');

Thank you!

petersirka avatar Jun 30 '17 10:06 petersirka

@petersirka cool. Thanks for explanation ;)

trsh avatar Jun 30 '17 10:06 trsh