Keycloak : custom ExecuteAction Mail, is it possible to get a user custom attribute? - html-email

I'm a trying to send a custom mail to my Keycloak user by overiding the executeAction mail template of keycloak.
I have created :
../myProject/email/text/executeAction.ftl
../myProject/email/messages/messages_fr.properties
../myProject/email/html/executeAction.ftl
I already got a mail working with this html/executeAction.ftl :
${msg("executeActionsBody",link, linkExpiration, realmName, requiredActionsText, linkExpirationFormatter(linkExpiration),user.getFirstName(),user.getLastName(),user.getUsername(),user.getAttributes())}
So I know that my configuration is good.
The problem with the above example is that I show a list of user custom attributes when I only want to get one:
gender=Mr or gender=Mrs
I tried using the function that I saw there :
https://github.com/keycloak/keycloak/blob/4.5.0.Final/server-spi/src/main/java/org/keycloak/models/UserModel.java
which give the following :
<#assign gender= user.getAttributes(gender)/>
${msg("executeActionsBody",link, linkExpiration, realmName, requiredActionsText, linkExpirationFormatter(linkExpiration),user.getFirstName(),user.getLastName(),user.getUsername(),gender)}
I expected to receive a mail with the user gender inside, but no mail is sent:
I have the following error :
ERROR [org.keycloak.services] (default task-1) KC-SERVICES0029: Failed to send email: javax.mail.MessagingException: IOException while sending message;
nested exception is:
java.io.IOException: Exception writing Multipart
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1308)
at org.keycloak.email.DefaultEmailSenderProvider.send(DefaultEmailSenderProvider.java:142)
at org.keycloak.email.freemarker.FreeMarkerEmailTemplateProvider.send(FreeMarkerEmailTemplateProvider.java:251)
.......
Caused by: java.io.IOException: Exception writing Multipart
at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:83)
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:897)
at javax.activation.DataHandler.writeTo(DataHandler.java:330)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1652)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1850)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1259)
... 84 more
Caused by: javax.mail.MessagingException: Empty multipart: multipart/alternative;
boundary="----=_Part_0_165447285.1560929205027"
at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:548)
at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:81)
... 89 more
I don't understand what exactly is going wrong :
Is my ftl bad ? I'm no expert but from what I saw, it should be ok.
It looks like keycloak is trying to send the mail, so why suddenly it fail when I try to use a single attribute instead of the full list ?
An other option might be to use some kind of regexp in the .ftl to extract the gender but I don't know if it's possible ?
Edit : Ok, I found out after many trial and error how to do it :
I guess my lack of knowledge about FTL is the problem. I got it working by doing this :
<#assign attributes = user.getAttributes()>
<#assign civilite = attributes.civilite?capitalize>
${msg("executeActionsBody",link, linkExpiration, realmName, requiredActionsText, linkExpirationFormatter(linkExpiration),user.getFirstName(),user.getLastName(),user.getUsername(),civilite)}
I have no idea why I needed to drop the ${} part or why you would get the value in HashMap> by doing attributes.key instead of using a getter but well it works...

Ok, I found out after many trial and error how to do it :
I guess my lack of knowledge about FTL is the problem. I got it working by doing this :
<#assign attributes = user.getAttributes()>
<#assign civilite = attributes.civilite?capitalize>
${msg("executeActionsBody",link, linkExpiration, realmName, requiredActionsText, linkExpirationFormatter(linkExpiration),user.getFirstName(),user.getLastName(),user.getUsername(),civilite)}
I have no idea why I needed to drop the ${} part or why you would get the value in HashMap> by doing attributes.key instead of using a getter but well it works...

Related

How to use Talend for a Rest API Post?

I'm using Talend Open Studio for ESB - Version: 8.0.1. I have a job that loops thru data and creates a CSV for each data element, like this:
> ID DATA
> A QQQQ#$%$
> B WWWE^UTU
etc. The job creates FileA.csv, then FileB.csv etc. That all works, but the next step I need will take FileA.csv and POST that data to an API.
The URI for each file is different, so I'm using a context to create the link. The links look like this:
https://:#host/updatenodes?application_code=fileA
There is a different application code for each file. I've tested the link for these files in Postman, and they all work, here's the message:
"result": "success",
"message": "Update batch submitted with 0 items",
"threadId": []
So, the links are correct. In Talend ESB, I'm using a tFileFetch object with Post Method checked. The file image_Tal.png shows the settings
of the tFileFetch. When I use a context URL, I get this error:
> Exception in component tFileFetch_1 (Cognosos)
> java.lang.IllegalArgumentException: host parameter is null
I also tried hard-coding the full URL into the filefetch object, I get this error:
Sep 08, 2022 1:49:39 PM org.apache.commons.httpclient.HttpMethodDirector executeWithRetry
INFO: I/O exception (java.net.ConnectException) caught when processing request: Connection timed out: no further information
So, how do I post the data from the CSV to the API? I've tried tRest, but it wouldn't allow me to use a context variable as the URI.
Because each different file has a different ID/Password, I need to use a variable for each iteration in the loop. When I use a
context for the URI, it gives me the error "URI is not absolute". I had the same problem with RestRequest and RestClient.
Are there some settings I need to add to Talend ESB? I'm using the defaults now - I'm not sure what settings to change.
![enter image description here](https://i.stack.imgur.com/A6NA3.png)
I've tried the tRest and tRestRequest objects, but I got and error using a context for the URI. I'm trying to get the CSV data to POST to the API.

syntax error in replace expression for subject making in access

i am very new to expressions in access,
In my access data base i need to parse some fields into subject of the outlook when send mail button clicked in the form , for this i am using replace expression as below :
=Replace(Replace("Rework |1: Reason|2:Drawing Number|3","|1",Nz([Order_Number],"")),"|2",Nz([Reason_for_rework],"")),"|3",Nz([Drawing_Or_Mat_Number],""))
but for this i am getting error as :
"the 'emaildatabaseobject' macro action has an invalid value for the 'subject' argument
Kindly help me how to solve this
You syntax is completely off. You may have Choose in mind:
=Choose(YourCategoryID,Nz([Order_Number],""),Nz([Reason_for_rework],""),Nz([Drawing_Or_Mat_Number],""))

Create Order status code 400 - Server Error

I'm trying to build a simple payment flow using Bluesnap. Currently I've been able to capture the users billing information using Hosted Fields, and then saved it to a "Shopper" in bluesnap. Now I'm trying to use the same Shopper to create an order (https://developers.bluesnap.com/v8976-Extended/docs/create-order), but I can't get it to work.
I'm sending this:
<order>
<ordering-shopper>
<shopper-id>
--Shopper ID--
</shopper-id>
<web-info>
<ip>127.0.0.1:61106</ip>
<remote-host>www.merchant.com</remote-host>
<user-agent>Mozilla/5.0 (Linux; X11)</user-agent>
</web-info>
<fraud-info>
<fraud-session-id>1234567890</fraud-session-id>
</fraud-info>
<authorized-by-shopper>true</authorized-by-shopper>
</ordering-shopper>
<cart>
<cart-item>
<sku>
<sku-id>2425735</sku-id>
</sku>
<quantity>1</quantity>
</cart-item>
</cart>
<expected-total-price>
<amount>15.00</amount>
<currency>USD</currency>
</expected-total-price>
</order>
Using a POST-request to BLUESNAPDOMAINPATH/services/2/orders
The only response I get is a status code 400 with the body containing "Server Error"
Does anyone know how to solve this issue?
Your root xml element is missing the namespace:
<order>
Should be:
<order xmlns="http://ws.plimus.com">

VTIGER REST API Query string not accepting fields SELECTION

my simple GET request with firstname field:
<service_url>?operation=query&sessionName=<sessionID>&query=select%20*%20firstname%20from%20Contacts;
This yields the following response error:
{"success":false,"error":{"code":"QUERY_SYNTAX_ERROR","message":"Syntax Error on line 1: token 'firstname' Unexpected Unknown(firstname), expected one of: FRM,COMMA"}}
While if i just leave out the "firstname" field selection it works well:
<service_url>?operation=query&sessionName=<sessionID>&query=select%20*%20from%20Contacts;
yeilding a full JSON list of contacts and their details.
what am i missing here?
Why do you add star (*) in front of firstname ?
I just tested the following GET request in a browser:
https://your_vtiger_url/webservice.php/?operation=query&query=select%20firstname%20from%20Contacts;&sessionName=3151a01859207d8359052
and it worked just fine. Try using the same URL structure by replacing the base URL and sessionName. Test it in a browser first (if you haven't).

silverlight2 Message class missing CreateBufferedCopy method

I am trying to read a soap response twice and I got the error message already read ... There are some examples how to avoid this BUT ... they are using the CreateBufferedCopy method and I cannot find it on the silverlight2 Message object:
Microsoft has also this sentence in the silverlight doc :
http://msdn.microsoft.com/en-us/library/system.servicemodel.channels.message.getreaderatbodycontents(VS.95).aspx
"If you want to access the body multiple times, use CreateBufferedCopy(Int32) to create a MessageBuffer instance."