Just tried learning Apache Camel.
I am trying to read gmail inbox unread mail.
I got the code snippet while searching but not able to get success from it.
if someone point out the mistake,
PollingConsumer pollingConsumer = null;
CamelContext context = new DefaultCamelContext();
Endpoint endpoint = context.getEndpoint("imaps://imap.gmail.com?username=" + mailId + "&password=" + password + "&delete=false&peek=false&unseen=true&consumer.delay=6000&closeFolder=false&disconnect=false");
System.out.println("end point:"+endpoint);
pollingConsumer = endpoint.createPollingConsumer();
System.out.println("polling consumer:"+pollingConsumer);
pollingConsumer.start();
pollingConsumer.getEndpoint().createExchange();
System.out.println("Exchange is created:");
Exchange exchange = pollingConsumer.receive();
System.out.println("pollingConsumer.receive()");
pollingConsumer.receive(); is getting blocked, I have unread mail in my mailbox.
Also I tried pollingConsumer.receive(6000); but it returns null.
I enable IMAP access in Gmail settings. is there any thing I am missing?
Let me write the solution, It will help someone facing similar issue .
Actually I have added java mail jar, but imap jar was missing and it was not displaying any error for this.
That is why I was not able to figure out the actual cause.
After browsing the parameters of "imaps://imap.gmail.com", I came across "debugMode" parameter which by default is false. when I added that parameter with value true, then it complained of missing jar on my console. After adding that jar thinks work perfectly.
Thanks for help.
Related
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
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?
I have this really weird problem and I'm not able to find a solution... I hope you can help me...
I'm working in Google App Engine to build my App (lets call it "MyApp"), to test, I have a cloned app renamed as "sandbox-MyApp".
I need to allow my users send a mail with some data, so I have a form where they can fill some information that will be added to the message.
I've working with this scenario a long time ago, but now I'm having issues, because, for some reason, my out-coming mails are not being received by the recipients...
It's a really weird thing about this, because, I can send one or two mails without problem, but after that, they suddenly stop, and after some code-changes, they work again.
I'm using Java.Mail to do the work,
I'm trying to send a simple HTML,
My "from" address is something like "userName#sandbox-myApp.appspotmail.com"
My Subject its something like: "Hello userName! There is some important message for you"
The message it's really simple, includes an image logo (served by an https://sandbox-myApp.appspot.com/img/logo.png), an invitation text and a single link to my app URL... (https://sandbox-myApp.appspot.com/)
My code it's real simple, based on the Google Documentation.
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(senderAddress, MimeUtility.encodeText(senderLabel, "UTF-8", "B"), "UTF-8"));
msg.addRecipient(javax.mail.internet.MimeMessage.RecipientType.TO, new InternetAddress(receiverAddress, receiverLabel, "UTF-8"));
if(responseAddress != null && !responseAddress.trim().isEmpty()){
msg.setReplyTo(new Address[] {
new InternetAddress(responseAddress, MimeUtility.encodeText(senderLabel, "UTF-8", "B"))
});
}
msg.setSubject(MimeUtility.encodeText(subject, "UTF-8", "B"), "UTF-8");
msg.setContent(msgBody, "text/html;charset=UTF-8");
Transport.send(msg);
I've tried changing "from" to something like "app_admin#mydomain.com" and it works for a while, but after some mails (about 5 or 6), stop working too.
Most shocking thing: There aren't any error message on logs... The Cuota Viewer counts every sent mail (so I suppose it must being blocked somewhere else),
I've modiffied the message to omit any URL on the body and It works better, but I need to include it!.
Problem is tracked on https://code.google.com/p/googleappengine/issues/detail?id=12786
Workaround which worked for my application is to not use appspot.com domain.
Register custom domain for the application and then mails to the application using the custom domain work.
Ok, how can Javax.mail check if an email is existing?
Let say I sent a message from a#cc.com to b#cc.com using Javax.mail. b#cc.com does not exist but Javax still saying that it sent the message OK. That is just like you email to a non-existent email in Yahoo mail or Gmail, even the destination email is non-exist, you still can be able to email it, & you only know that destination email does not exist after many hours when Gmail or Ymail returns a "failure recipient sending" or something like that.
Someone said that we can use MX record but they did not clearly how to use Javax to achive that. I doubt that solution.
Can you find a solution for it?
You will not be able to make sure that the address exists. Due to the distributed structure of the internet, the knowledge of whether an address exists is not available at one central point.
What you could do is check whether the domain to which the email is sent (cc.com in your example) exists and therefore if there's a chance of your email arriving. The idea of using the MX record is basically this; you can check which server would be responsible for the delivery of your email.
Refer This Question and Oracle Article To solve your problem.
You can get detailed delivery report whether your email is sent or not to correct email id. There's exception, if wrong email id is entered and it is available it will to it.
My problem is I get error while trying to get request token from Yahoo. The error says Im missing oauth_callback parameter and yes I miss it because I dont need it. Ive read I need to set it to "oob" value if I dont want to use it(desktop app). And I did that but to no avail. If I set it to null the same happens. Im using OAuth for java: http://oauth.googlecode.com/svn/code/java/core/
OAuthServiceProvider serviceProvider = new OAuthServiceProvider("https://api.login.yahoo.com/oauth/v2/get_request_token",
"https://api.login.yahoo.com/oauth/v2/request_auth",
"https://api.login.yahoo.com/oauth/v2/get_token");
OAuthConsumer consumer = new OAuthConsumer("oob", consumerKey, consumerSecret, serviceProvider);
OAuthAccessor accessor = new OAuthAccessor(consumer);
OAuthClient client = new OAuthClient(new HttpClient4());
OAuthMessage response = client.getRequestTokenResponse(accessor, OAuthMessage.POST, null);
System.out.println(response.getBodyAsStream());
Have you tried using Scribe?
I also had problems with OAuth java libs so I developed that one. It's pretty much cross provider and better documented than the one you're using.
If it does not work with Yahoo you can easily extend it creating your own Provider
Hope that helps!
there is a problem in the java OAuthMassage class, I resolved it by adding to addRequiredParameters method thie line
if (pMap.get(OAuth.OAUTH_CALLBACK) == null) {
addParameter(OAuth.OAUTH_CALLBACK, consumer.callbackURL);
}
if you still have this problem I can help you: rbouadjenek#gmail.com
I haven't used that library, but it looks like it isn't properly handling the callback URL. Since OAuth 1.0a (http://oauth.net/advisories/2009-1/ and http://oauth.net/core/1.0a/), the callback URL needs to be sent in the first call to get the request token (not in the client-side call to authorise it), and it seems that this library hasn't been updated to do this (at least from looking at the code). I assume that Yahoo requires the parameter to be there.
Not sure if the original problem was ever solved, but wanted to point to a new Java OAuth SDK that Yahoo released last week:
http://developer.yahoo.net/blog/archives/2010/07/yos_sdk_for_java.html
Developers trying to access Yahoo's services via OAuth with Java may find parts of this SDK helpful.