I am trying to send email in NestJs but seems to stuck at a weird error.
TypeError: Cannot destructure property 'templateName' of 'precompile(...)' as it is undefined.
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at new NodeError (node:internal/errors:363:5)
at ServerResponse.setHeader (node:_http_outgoing:573:11)
I am not sure what's going on the only solution I was able to find was to put ''./'' in front of the template names but I am not sure why would that work also it isn't even working in my case.
This is how i am trying to send it
this.mailService.sendEmail(
emailAddress,
[], // cc
[], // bcc
"Pretty Subject Line", // subject
"./verify-email", // template
{ // context
name: "tetsName",
verifyLink
}
);
templates folder is in root directory
Cannot set header error mostly occurs when you are sending a response after once you have sent a response. Take a look at the following code
//This does not work
res.send("This is a Response");
res.send("This is a second response");
If you are doing something like this, then it won't work. Try a logic that does all the tasks you want in one go or use may
res.write("This is a response"):
res.end();
For me,this is a template file path issue. Review your template.dir in your MailerModule config, and compare it to your project "dist" directory. if your template file path is "dist/templates/template.hbs" then your template.dir should be ${process.cwd()}/templates else if your dist directory is "dist/src/templates/template.hbs" ,which is depend on your compile configs. then your template.dir config should be join(__dirname, 'templates')
Related
I have done everything needed to setup webservices on my moodle 3.11 instance, including roles/capabilities/user. However sending a test request always gives {
"exception": "dml_missing_record_exception",
"errorcode": "invalidrecord",
"message": "Can't find data record in database table external_functions."
}
The URL to access it is of the format https:///moodle/webservice/rest/server.php?wsfunction=core_user_create_user&service=mymoodleusermanage&moodlewsrestformat=json&users[0][username]=ABC&users[0][firstname]=VPTest&users[0][lastname]=None&users[0][email]=mail#xxx.com&users[0][password]=xxxxx&users[0][auth]=manual&wstoken=xxxxxxxxxxxxxx
The service parameter is correctly set to the shortname of the service. Does the service have to be defined anywhere additionally apart from Site Administration->Server->Web Services->External Services->Custom Services
Thanks for any help that can be given
The answer is very simple - you are trying to call a non-existent webservice function (hence the error message about being unable to find the database record for the function in the external_functions database table).
If you look in the Moodle code: https://github.com/moodle/moodle/blob/master/lib/db/services.php#L1717 you will see that the function is called core_user_create_users - with an "s" at the end of it.
If you add that extra "s" into the URL parameters you are using, then it should work.
https:///moodle/webservice/rest/server.php?wsfunction=core_user_create_user&service=mymoodleusermanage&moodlewsrestformat=json&users[0][username]=ABC&users[0][firstname]=VPTest&users[0][lastname]=None&users[0][email]=mail#xxx.com&users[0][password]=xxxxx&users[0][auth]=manual&wstoken=xxxxxxxxxxxxxx
you must change username all character small letter [username]=ABC like this [username]=abc and add s wsfunction=core_user_create_users
I'm running one of the examples in my own project and running into the error.
Action Error: Missing result from request body
Github Sample Project: dialogflow-silly-name-maker-webhook-nodejs
Hookbin: Shows the webhook coming from the assistant.https://hookbin.com/bin/ZjPzJ1Yb
Might there be an error in the sample code or in my set-up?
I was getting this error. In my case it was because the request object I was passing to ActionsSdkApp() constructor had a body property which was a JSON string as opposed to data structure.
Adding this in before instantiating ActionsSdkApp fixed it for me...
request.body = JSON.parse(request.body);
Then I could carry on like this...
App = new ActionsSdkApp({'request': request, 'response': response});
That error message is printed by the Action on Google client library if the incoming request doesn't have the intent information, but your JSON looks good.
Make sure your action enables debug logging for the client library: process.env.DEBUG = 'actions-on-google:*';
Then study the complete log to understand your issue.
I'm using Jenkins 2.2 and email-ext plugin 2.42 (both current, as are all of the rest of my plugins). I have my global configuration set to have a single, explicit recipient and my project is using default email notification configuration (that is, send to $DEFAULT_RECIPIENTS). I have also set an explicit recipient in the project. In both configurations, the console output for the job says:
An attempt to send an e-mail to empty list of recipients, ignored.
This would seem to be https://issues.jenkins-ci.org/browse/JENKINS-13583 except
1. that was marked as resolved four years ago, and 2. I get e-mail when I use basic, built-in notifications. Does anyone else see this problem with email-ext?
Turns out plugin configuration is somewhat non-intuitive; a necessary setting is buried behind an Advanced button. I got answers in https://issues.jenkins-ci.org/browse/JENKINS-34731 and it is working now as follows:
In the Advanced settings, Triggers -> Failure - Any lists "Developers" by default, but not "Recipient List."
For those using this plugin in combination with Job DSL. I have do add the sendTo { recipientList() } block explicitly to the different triggers.
So my DSL looked like this:
extendedEmail {
recipientList('${EMAIL_RECIPIENTS}')
triggers {
failure {
subject('The subject')
content("The content")
sendTo {
recipientList()
}
}
}
}
Instead of using $DEFAULT_RECIPIENTS use to:
emailext(
to: 'somename#emailprovider.com',
body: '${DEFAULT_CONTENT}',
mimeType: 'text/html',
subject: '${DEFAULT_SUBJECT}',
replyTo: '$DEFAULT_REPLYTO'
)
}
Ref: https://stackoverflow.com/a/39499554/1134084
I finally found the problem through repeated attempts. There is no need for such trouble at all. The reason is that in the advanced Settings of Editable Email Notification trigger condition, the Recipient List is empty by default, and all your Settings outside will be overridden. An attempt to send an e-mail to empty list of recipients was ignored. An attempt to send an E-mail to empty list of recipients ignored.
I am using the Email Ext Jenkins plugin and it was working quite well.
Now I need to set the recipients list dynamically. Basically for each build I get a list of email recipients in a file and I need to use that list. My question is:
Is there a way to set an Environment Variable so that that can be modified and Recipient List will get that consume that environment variable.
I know there is a solution to set programmatically recipients of Jenkins Email-ext plugin in the pre-send script.How To set programmatically recipients of jenkins email ext plugin. However for my case there are some difficulty with that solution as I need to read a file which contains a list of Emails.
If the format of the file is either comma separated or space separated, you could just use the FILE token (see the content token reference in the plugin). That should put the contents of the file into the recipients list.
I can't test this right now so I can't remember if apache commons is available.
Create a file called recipients.groovy with the following contents:
<%
def stream = new FilePath(build.workspace, "yourfile.txt").read();
def recipients = IOUtils.toString(stream, "UTF-8");
%>
${recipients}
And in your jobs configuration, in the recipients list, you put ${SCRIPT, script="recipients.groovy"}
API References:
FilePath
AbstractBuild
Referring to the recipients.groovy in the Recipient List, gives the following exception:
Failed to create e-mail address for Error in script or template: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script1.groovy: 1:
unexpected token: < # line 1, column 1. <% ^ 1 error
Full Exception below:
groovy.lang.MissingPropertyException: No such property: build for class: Script1
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:50)
at org.codehaus.groovy.runtime.callsite.PogoGetPropertySite.getProperty(PogoGetPropertySite.java:49)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGroovyObjectGetProperty(AbstractCallSite.java:231)
at Script1.run(Script1.groovy:4)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:580)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:618)
at groovy.lang.GroovyShell.evaluate(GroovyShell.java:589)
at hudson.util.RemotingDiagnostics$Script.call(RemotingDiagnostics.java:150)
at hudson.util.RemotingDiagnostics$Script.call(RemotingDiagnostics.java:122)
at hudson.remoting.LocalChannel.call(LocalChannel.java:45)
at hudson.util.RemotingDiagnostics.executeGroovy(RemotingDiagnostics.java:119)
at jenkins.model.Jenkins._doScript(Jenkins.java:3400)
at jenkins.model.Jenkins.doScript(Jenkins.java:3377)
at sun.reflect.GeneratedMethodAccessor344.invoke(Unknown Source)
You can use the Inject environment variables plugin (https://wiki.jenkins-ci.org/display/JENKINS/EnvInject+Plugin) and to create a var during run time, or the Propagate build environment variables (https://wiki.jenkins-ci.org/display/JENKINS/Build+Env+Propagator+Plugin) to change an existing one, and then you can use this var in the Project recipient list when you are using Editable Email Notification (https://wiki.jenkins-ci.org/display/JENKINS/Email-ext+plugin)
We built an app in Zend Framework (v1) and have not worked a lot in setting up error reporting and logging. Is there any way we could get some level or error reporting without too much change in the code? Is there a ErrorHandler plugin available?
The basic requirement is to log errors that happens within the controller, missing controllers, malformed URLs, etc.
I also want to be able to log errors within my controllers. Will using error controller here, help me identify and log errors within my controllers? How best to do this with minimal changes?
I would use Zend_Log and use the following strategy.
If you are using Zend_Application in your app, there is a resource for logging. You can read more about the resource here
My advice would be to choose between writing to a db or log file stream. Write your log to a db if you plan on having some sort of web interface to it, if not a flat file will do just fine.
You can setup the logging to a file with this simple example
resources.log.stream.writerName = "Stream"
resources.log.stream.writerParams.stream = APPLICATION_PATH "/../data/logs/application.log"
resources.log.stream.writerParams.mode = "a"
resources.log.stream.filterName = "Priority"
resources.log.stream.filterParams.priority = 4
Also, I would suggest sending Critical errors to an email account that is checked regularly by your development team. The company I work for sends them to errors#companyname.com and that forwards to all of the developers from production sites.
From what I understand, you can't setup a Mail writer via a factory, so the resource won't do you any good, but you can probably set it up in your ErrorController or Bootstrap.
$mail = new Zend_Mail();
$mail->setFrom('errors#example.org')
->addTo('project_developers#example.org');
$writer = new Zend_Log_Writer_Mail($mail);
// Set subject text for use; summary of number of errors is appended to the
// subject line before sending the message.
$writer->setSubjectPrependText('Errors with script foo.php');
// Only email warning level entries and higher.
$writer->addFilter(Zend_Log::WARN);
$log = new Zend_Log();
$log->addWriter($writer);
// Something bad happened!
$log->error('unable to connect to database');
// On writer shutdown, Zend_Mail::send() is triggered to send an email with
// all log entries at or above the Zend_Log filter level.
You will need to do a little work to the above example but the optimal solution would be to grab the log resource in your bootstrap file, and add the email writer to it, instead of creating a second log instance.
You can use Zend_Controller_Plugin_ErrorHandler . As you can see on the documentation page there is an example that checks for missing controller/action and shows you how to set the appropriate headers.
You can then use Zend_Log to log your error messages to disk/db/mail.