sendmailR: how to handle occasional "Unknown SMTP code" errors - r

I'm using sendmailR in my R script to send notifications.
Sometimes notification fails with the following error:
Unknown SMTP code: 452
Error in if (code == lcode) { : argument is of length zero
Execution halts.
How can I handle such errors, so that even if notification fails the script runs on?

Wrap the try function around sendmail (assuming you use sendmail, if not then wrap it around the function or code that produces the error) this way:
try(sendmail(from,to,subject), silent=T)
You can set silent to FALSE if you want the error message to appear but still continue with the process

Related

httr authentication login/password in "xtb" API

I need to authenticate and get prices using this api
I have no experience with api so my attempt to login gives an error
login <- "vikov98261#jesdoit.com"
pass <- "QazQaz123"
library(httr)
resp <- POST("xapi.xtb.com",
body=list(userId = login,
password = pass) )
Error in curl::curl_fetch_memory(url, handle = handle) :
Failed to connect to xapi.xtb.com port 80: Timed out
Can someone show me how to do it right.
I would like an example of how the login request works.
And also I would like an example of how to get the prices of any currency
Their API documentation uses WebSocket syntax, so I assume xapi.xtb.com may only be used by the clients. I, for once, only managed to get WebSocket to work.
In order to make this work in r you would need a WebSocket client library for r, such as websocket. Once you have that:
1. Define connection
ws <- WebSocket$new("wss://ws.xtb.com/demo")
2. Log in
WebSocket clients work with events. The 'open' event is generated once the connection is established and the 'message' events are generated when messages are received. You need to write handlers for them to orchestrate the way you want to use the XTB API.
The first event will be 'open', so use that to send the login command.
ws$onOpen(function(event) {
ws$send({
"command":"login",
"arguments": {
"userId":"1000",
"password":"PASSWORD",
"appId":"test",
"appName":"test"
}
})
})
3. Your logic
The response to your login command will trigger a 'message' event, the output of which you will need to handle in your code.
ws$onMessage( <your-code-goes-here> )
The easiest way would probably be to send new commands based on what is the structure of the received message, although it can get really complicated with many commands.
4. Connect
After all handles have been defined, don't forget to connect.
ws$connect()

MULE-4:VM: Check number of messages in VM queue before consuming

We required to consume messages from VM in a flow. Currently it is throwing an error when VM is empty as below:
Message : Tried to consume messages from VM queue 'FQ' but it was empty after timeout of 5 SECONDS Payload Type : org.mule.runtime.core.internal.streaming.bytes.ManagedCursorStreamProvider
For now we wrapped it in try catch block and handling this error(still it is printing the error stack trace, we want to avoid it)
I want to check is there a way or piece of code that can be used for checking the number of messages available in VM before consuming it.
You can use the logException attribute on the error handler so the exception is not printed in the log.
Example:
<try doc:name="Try">
<vm:consume doc:name="Consume" config-ref="VM_Config" queueName="q1" />
<error-handler >
<on-error-continue enableNotifications="true" logException="false" doc:name="On Error Continue" type="VM:EMPTY_QUEUE">
<logger level="INFO" doc:name="Logger" message="consume timeout"/>
</on-error-continue>
</error-handler>
</try>

Do not print stack trace on Postfix's mail delivery failure notification

When our service fails to deliver an email, the rejection notification returned to the sender contains the stack trace of the code that failed. Is there a way to send the delivery notification, without the attached errors?
We have a postfix server that handles incoming emails in a catchall python script. That script uploads the email to one of our services and throws an exception in case it failed.
This is the template we are using
failure_template = <<EOF
Charset: us-ascii
From: MAILER-DAEMON (Mail Delivery System)
Subject: Undelivered Mail Returned to Sender
Postmaster-Subject: Postmaster Copy: Undelivered Mail
This is the mail system at host $myhostname.
I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.
For further assistance, please send mail to <postmaster>
If you do so, please include this problem report. You can
delete your own text from the attached returned message.
The mail system
EOF
Expected result would be just the template notification, without the strack trace of the catch-all script.
The mail server simply includes in the bounce whatever your Python program displays on its standard error. Maybe call the script via a wrapper which saves the standard error to a sane place (or even discards it, if you are sure it never contains anything useful).
#!/bin/sh
python3 /path/to/deliver.py 2>>/var/log/deliver.log
Your mail server obviously needs to have write access to the log, and you'll probably want to set up periodic log rotation for the file.
Probably a better overall approach is for the Python program to not crash.

NopCommerce: Error while running the 'Keep alive' schedule task

We are having this strange error. When the keep alive task tries to run, it gives this error: Error while running the 'Keep alive' schedule task. The remote server returned an error: (403) Forbidden.
But when i try to run keep alive manually on the browser via example.com/keepalive/index it runs perfectly.
Our task code:
string url = "https://www.example.com/keepalive/index";
using (var wc = new WebClient())
{
wc.DownloadString(url);
}
We are using NopCommerce 3.70. What are we missing here?
You can check this:
Check your store Url from Admin -> Configuration -> Stores.
Edit your particular store from list and check Store URL might be not same with your browser URL.
Due to this reason you get error like Error while running the 'Keep alive' schedule task. The remote server returned an error: (403) Forbidden.
So please enter correct store URL and restart application.
It will resolved your issue.

ZendeskR Producing the following error when trying to connect to api

I am fairly new to using APIs and trying to use the zendesk API now through R using the ZendeskR package. I belive I have connected to it however I keep getting the following error whenever I try to query it.
Here is my code:
library(zendeskR)
library(rjson)
zendesk(username, password, url)
ticket <- getTicket('20150')
The username, password and url are all variables that I have assigned the correct values.
The following error that I get when I run it is this:
Error in function (type, msg, asError = TRUE) :
error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
Please help as I am unsure on what this error means or what I am doing wrong.
Thanks.
TLS v1.1 is no longer accepted by Zendesk, please use TLS v1.2.

Resources