Using Mailjet API in Grails application for sending mails - java

I want to integrate Mailjet API in Grails application for sending mails, I have already used ASYNC mail API for sending mail in grails, in this api , I need to give configuration parameters in config.groovy. Now as I am using Mailjet for sending mails, so I need to give Mailjet SMTP settings in config.groovy, so I give as follows :
grails {
mail {
host = "in.mailjet.com"
port = 465
username = "xxx#gmail.com"
password = "xxx"
props = ["mail.smtp.host": "in.mailjet.com",
"mail.smtp.socketFactory.port": "465",
"mail.smtp.socketFactory.class": "javax.net.ssl.SSLSocketFactory",
"mail.smtp.auth":"true",
"mail.smtp.port": "465",
"mail.smtp.user": "API key of mailjet",
"mail.smtp.password": "secret key of mailjet"]
}
}
Here is the example of sending mail using java code
What am I doing wrong?

username and password have to contain your api key and the api secret, not the credentials
that you use to log into the web site.
Using mail.smtp.host as a property is redundant and should not be necessary.

Related

how to use azure ad without client secret just with client id and tenant id?

My question is how to apply user authentication in web application using azure ad in case I don't have client secret. I just have client-id and tenant-id. I would appreciate your swift response.
AFAIK there is no need to use client secret in web application while we are authenticating with Azure AD.
While authenticating your App with Azure AD, your code snippet will be something like below:
{
"AzureAd": {
"Instance": "https://login.microsoftonline.com/",
"ClientId": "*******************************",
"TenantId": "*******************************",
"CallbackPath": "https://localhost/signin-oidc"
}
If you want to get access token via Postman without using client secret, you can make use of ROPC flow like below:
In Postman, Go to Authorization tab and select type as Oauth2.0
Go to Headers tab and include Content-Type key and give value as application/x-www-form-urlencoded
In Body tab, include parameters like client_id, grant_type, username, password and scope as below:
And you will get the access token like below:

Using Cognito Authentication with Elastic Load Balancer

I have a ReactJS front end website which uses AWS Cognito for authentication, this is working fine, I can sign in, up, out, etc. My back end is a set of Java web services running in Docker containers in AWS Fargate all behind an Elastic Load Balancer.
I noticed that in the ELB, you can add Authentication to the listeners which will check the HTTP header for the jwt token and authenticate it before forwarding to the relevant micro service. I've come a cross an issue where when I set the 'Authenticate...' rule, it comes back with an error that I need to add a client secret. I can't add a client secret to my Cognito setup because I'm accessing it from ReactJS and apparently Javascript doesn't work with Cognito with Client Secret added.
So if I can't use this method, I need some way of authenticating HTTPS requests when they get to my Java microservices. From my Java service, it feels like I need to somehow access AWS Cognito to check the user session but that feels wrong.
Any ideas how this should work?
Thanks
You can consider to use pure JS to authenticate with AWS Cognito without client secret which is an optional. I did create a App Client without Client Secret and it did work.
Reference: https://docs.aws.amazon.com/cognito/latest/developerguide/authentication.html
// Amazon Cognito creates a session which includes the id, access, and refresh tokens of an authenticated user.
var authenticationData = {
Username : 'username',
Password : 'password',
};
var authenticationDetails = new AmazonCognitoIdentity.AuthenticationDetails(authenticationData);
var poolData = {
UserPoolId : 'us-east-1_ExaMPle',
ClientId : '1example23456789'
};
var userPool = new AmazonCognitoIdentity.CognitoUserPool(poolData);
var userData = {
Username : 'username',
Pool : userPool
};
var cognitoUser = new AmazonCognitoIdentity.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
var accessToken = result.getAccessToken().getJwtToken();
/* Use the idToken for Logins Map when Federating User Pools with identity pools or when passing through an Authorization Header to an API Gateway Authorizer */
var idToken = result.idToken.jwtToken;
},
onFailure: function(err) {
alert(err);
},
});
Also, as you are using ReactJS, you can try Amplify:
https://aws-amplify.github.io/docs/js/authentication
I understand that while you have so many layers and sometimes you want to configure it as you want, you can try to make yourself a simple authenticating function with AWS Lambda.

AADSTS70002: Error validating credentials. AADSTS50012: Client assertion is not within its valid time range

I am using Microsoft Java SDK to connect to Azure cloud.
I have created a certificate (p12 file) from .crt,.key & root.crt.
I have uploaded the .crt under Azure AD>App Registrations >Settings>Upload public key.
After that from my Java code I tried to get Azure client (Authenticate) by passing p12 content and password to below API:
ApplicationTokenCredentials credentials = new ApplicationTokenCredentials();
public ApplicationTokenCredentials(String clientId, String domain, byte[] certificate, String password, AzureEnvironment)
Azure azure = Azure.authenticate(credentials).withSubscription(SUBSCRIPTION_ID);
The above call is successful. But if we try to get azure.networks() or azure.storage() it fails with below error:
AADSTS70002: Error validating credentials. AADSTS50012: Client assertion is not within its valid time range.
Please help me on this.
According to Certificate credentials for application authentication, after upload the Public Key.
We also need to update the manifest
In the Azure app registration for the client application, open the application manifest, and replace the keyCredentials property with your new certificate information using the following schema:
"keyCredentials": [
{
"customKeyIdentifier": "$base64Thumbprint",
"keyId": "$keyid",
"type": "AsymmetricX509Cert",
"usage": "Verify",
"value": "$base64Value"
}
]
If cert is not manditory, we also could generate the secret with azure portal. After that we could get ApplicationTokenCredentials with follow way
public ApplicationTokenCredentials(String clientId,
String domain,
String secret,
AzureEnvironment environment)
Note: If we want to access the Azure resource,we also need to assgin Azure AD application to role.

DocuSign is not sending email to Signer

DocuSign is not sending email to Signer.
I have even followed below support link. I did not find any proper solution.
https://support.docusign.com/answers/00002292
while creating envelope I am using below code
Signer signer = new Signer();
signer.setEmail("***#gmail.com");
signer.setName("My Name");
and for generating URL for Iframe
RecipientViewRequest returnUrl = new RecipientViewRequest();
returnUrl.setReturnUrl("https://www.docusign.com/devcenter");
returnUrl.setAuthenticationMethod("email");
// recipient information must match embedded recipient info we provided
// in step #2
returnUrl.setEmail("***#gmail.com");
returnUrl.setUserName("My Name");
returnUrl.setRecipientId("1");
returnUrl.setClientUserId("10111");
I am using production account with valid promoted integrator key and DocuSign Java API.
***#gmail.com user should get an email after signing process. But he/She is not getting any email. DocuSign server is sending all emails to the user whose credentials were used for creating envelope and Iframe URL.
If you set the clientUserId property for a recipient, you're making them an embedded recipient, and (by default) DocuSign does not send emails to embedded recipients. This behavior is by design.
UPDATE
It seems that there's an account configuration setting (i.e., that you can set via the DocuSign web UI) that will make DocuSign send the 'envelope complete' email to embedded recipients. See info in this support thread for more info: https://support.docusign.com/en/answers/00008788.

Detect emails and response with a mail

If i got any email I want to response with a email from my code.
Am new to java, Is it possible with any api to detect mails?
I saw javamail api in this we can read and send mail. In this we need to pass server host. To read hotmail emails what host name we need to pass?
I find the following code.
Properties props =System.getProperties();
props.setProperty("mail.store.protocol","imaps");
Session session = Session.getDefaultInstance(props, null);
Store store = session.getStore("imaps");
store.connect("server hostname","username","password");
can u prefer any tutorials for that and property key values and server hosts.
http://www.javatpoint.com/example-of-receiving-email-using-java-mail-api
here the solution to read mails
For reading mail
http://www.compiletimeerror.com/2013/06/reading-email-using-javamail-api-example.html
and get the To Address and send mail using
http://www.tutorialspoint.com/java/java_sending_email.htm

Categories