gmail smtp exception in java play framework - java

I was reading about what is the best way about sending email through play framework (java). I have found this: https://github.com/playframework/play-mailer and I followed the instructions. I use gmail.
Here is what I added into application.conf:
play.mailer.host="smtp.gmail.com"
play.mailer.port=587
play.mailer.ssl=yes
play.mailer.tls=no
play.mailer.user="blabla#gmail.com"
play.mailer.password="blabla"
and here is my controller:
Email email = new Email();
email.setSubject("Confirmation");
email.setFrom("Mister FROM <test#gmail.com>");
email.addTo("Miss TO <test2#gmail.com>");
email.setBodyText("A text message");
email.setBodyHtml("<html><body><p>An <b>html</b> message</p></body></html>");
mailerClient.send(email);
Everything compiles with no problems, but when I run it I get this exception:
[EmailException: Sending the email to the following server failed : smtp.gmail.com:587] at mailerClient.send(email);

You have to change the change the gmail configuration also .
like-
Go to your gmail account then in setting section go to the "Forwarding and POP/IMAP" tab then enable "Enable IMAP".
Hope this will help if you are sending the correct credential.

Related

How to send a gmail with starred using java mail api

I tried to use Java mail API to send a gmail with starred. I read in many places and I added code as follows:-
if (mailHighPriority) {
msg.setHeader("X-Priority", "1");
msg.setHeader("Importance", "high");
msg.setHeader("priority", "Urgent");
msg.setHeader("x-msmail-priority", "high");
}
However, I am not able to set the Gmail as starred. Is there any other option for this? Thanks
STARRED is a label used by gmail. You can't set a label when sending a mail.
You need to set up a filtering rule or use the gmail api to apply labels to messages.

Authorization Exception While implementing "/messages" endpoint in sendgrid API

I am developing a jsf + spring application and in that trying to get all the emails send through the sendgrid api using the "/messages" endpoint .
I tried implementing the "/messages" endpoint in Java similar to the "/stats" endpoint mentioned in the example here. Below is my code
I am initializing the send grid object in my application context
<bean id="sendGrid" class="com.sendgrid.SendGrid">
<constructor-arg name="apiKey" value="my_api_key"/>
</bean>
Then I am using the autowired instance of that object in my service bean as follows:
com.sendgrid.Request request = new Request();
try {
request.setMethod(Method.GET);
request.setEndpoint("messages");
request.addQueryParam("limit", "10");
request.addQueryParam("query", "status='processed'");
com.sendgrid.Response response=sendGrid.api(request);
LOGGER.debug(response.getBody());
} catch (IOException e) {
LOGGER.error(ExceptionUtils.getStackTrace(e));
}
However I am receiving the following exception
Stack Trace:
java.io.IOException: Request returned status Code 400 Body:{"errors":[{"message":"authorization required"}]}
at com.sendgrid.Client.executeApiCall(Client.java:287)
at com.sendgrid.Client.get(Client.java:163)
at com.sendgrid.Client.api(Client.java:308)
at com.sendgrid.SendGrid.makeCall(SendGrid.java:203)
at com.sendgrid.SendGrid.api(SendGrid.java:225)
Since I am able to send e-mail and receive stats successfully. I don't think authorization should be the problem here. Am I going wrong somewhere or am I missing something?
Any guesses or leads welcome. Thanks
I contacted the sendgrid support team and It was an API Key issue. Since I was trying out the free account, I did not have access to that particular endpoint. However once I upgraded to a paid account with the email activity add on, It worked.
Yes, like Pranay said, You have to purchase Add-On named as "Extended Email Activity History" located at (once you logged in with send grid, look for) Settings → Account_Details → Product_Page → Scroll down to add-ons → then select "Extended Email Activity History" and add to your plan. (Current cost of this add-on is $12/month* & I don not understand meaning of * here)
You can check following link for sendgrid code snippet
https://docs.sendgrid.com/api-reference/e-mail-activity/filter-all-messages
Hope this helps
PK

attach itemAttachment to an email using ews java api

I am working on sending emails through ews.
In some scenarios, users wants to be able to get an email (parentEmail) with another email (emailToAttach) attached. This emailToAttach is retrieved from the sent folder and then attached to the parentEmail.
However, I am getting a stackoverflow error when I am trying to do the following at setSubject:
EmailMessage parentEmailMessage = new EmailMessage(exchangeService)
ItemAttachment attachment = parentEmailMessage.attachments.
<EmailMessage>addItemAttachment(Item)
attachment.setName(emailToAttach.subject)
attachment.item.setSubject(emailToAttach.subject)
attachment.item.setMimeContent(emailToAttach.mimeContent)
Can anyone help figure out why is the stack over flow error produced?

Keycloack - User not found message information not displayed when reset password

On my keycloak server, when i go to page "reset password" and i enter a bad username, the return message say "You should receive an email shortly with further instructions." But, i want to send a message like "username not found"
On the console log i see the error "user_not_found" and i don't understand why i don't see the same thing on server.
WARN [org.keycloak.events] (default task-31) type=RESET_PASSWORD_ERROR, realmId=XXX, clientId=XXX, userId=XXX, ipAddress=127.0.0.1, error=user_not_found, auth_method=XXX, redirect_uri=http://localhost/, code_id=XX, username=test
My keycloak server is on 3.4
Thanks
Forgot password has default implementation. If you want to change it you have to:
1. create your own provider for "Choose User";
2. create a new FLOW with it.
3. change bidings for Reset Credentials with new FLOW.
More information you can find on:
http://www.keycloak.org/docs/latest/server_development/index.html

box-java-sdk - Normal Authentication

I am trying to build an application with Box SDK in Java. Currently, I am connecting to my Box with a developer token:
BoxAPIConnection api = new BoxAPIConnection("MY-DEVELOPER-TOKEN");
I have to generate a new developer token every 60 minutes, therefore I would like to make it so this is done automatically. According to the Box API authentication doc, we can do it with:
BoxAPIConnection api = new BoxAPIConnection("MY-CLIENT-ID", "MY-CLIENT-SECRET", "MY-AUTH-CODE");
However, I get:
Exception in thread "main" com.box.sdk.BoxAPIException: The API returned an error code: 400
{"error":"invalid_grant","error_description":"Auth code doesn't exist or is invalid for the client"}
I get my Client ID and Client Secret from the configuration page of my Box account, so I assume these are correct. Where can I get my authentication code? The one I am using is the one from a pop-up window when I first connected to my account.
You can get the authentication code like this:
go to a browser and type in with your client_id:
https://account.box.com/api/oauth2/authorize?response_type=code&client_id=xxxxxx&state&state=security_token%3DKnhMJatFipTAnM0nHlZA
authorize the app and you'll get a code back (make sure your redirect is something like localhost
then use postman and do this (fill in the code w/ what you just got back)

Categories

Resources