If I get it right, you want to send a response based on the result on transport.send()
. If so you can just return it, like
return transport.send(envelope)
.then((success) => sentMsg = 'Message sent, thank you.' )
.catchError((e) => sentMsg = 'Message not sent; the reported error was: $e');
Or using Completer
var c = new Completer();
transport.send(envelope)
.then((success) => sentMsg = 'Message sent, thank you.' )
.then(c.complete)
.catchError((e) => sentMsg = 'Message not sent; the reported error was: $e');
return c.future;
And since you are returning a Future
, you have to change how you send your response to client, from
res.write(sendMail(postData));
res.close();
to
sendMail(postData)
.then((result) {
res.write(result);
res.close();
});