Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
Posts: 23
Registered: ‎08-06-2008
My Device: Not Specified

read messages

Hi, How i could read the messages of a email which it has configured in a blackberry?

Thx.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: read messages

Apologies, I'm not clear what you are asking.  However before you restate your question, I suggest you review the Chapter in the Developer Guide called "Using the message List" (chapter 11 in the 4.5 manual)
New Developer
Posts: 23
Registered: ‎08-06-2008
My Device: Not Specified

Re: read messages

Sorry, I dont write very good english. I have read that document but i have not very clear.

There are some examples to read email from the blackberry? I have implement to send.
Developer
Posts: 16,986
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: read messages

Here is an example to send a message (it is not checked if there is mail available though):

Store store = Session.getDefaultInstance().getStore();
Folder[] folders = store.list(Folder.SENT);
Folder sentfolder = folders[0];
net.rim.blackberry.api.mail.Message msg = new net.rim.blackberry.api.mail.Message(sentfolder);
// Specify the message contents
Address toAddress = new Address(mailAddress, name);
msg.addRecipient(net.rim.blackberry.api.mail.Message.RecipientType.TO, toAddress);
msg.setSubject(subject);
msg.setContent(messageText);
// Send the message
Transport.send(msg);
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
New Developer
Posts: 23
Registered: ‎08-06-2008
My Device: Not Specified

Re: read messages

Sorry, i need a example to read a message not to send.

 

New Developer
Posts: 23
Registered: ‎08-06-2008
My Device: Not Specified

Re: read messages

I am using a similary code GPSEmailing http://supportforums.blackberry.com/rim/board/message?board.id=java_dev&message.id=1770&query.id=163...  and i sending several positions at once in an email every hour, but i need to send a email to blackberry
to force the return email with the positions in that moment.
Thx.
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: read messages

In the Developer Guide, Chapter "Using the Mesage List", there is a Section called "Open a message" which does what you want I think.

 

In addition, you may find the following KB article useful.

 

How To - Access HTML email messages
Article Number: DB-00666

http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800698/How_To_...

 

 

New Developer
Posts: 23
Registered: ‎08-06-2008
My Device: Not Specified

Re: read messages

I using this code but dont work:

 

public boolean read(){

//Session s=Session

 boolean flag=false; try{

Store store = Session.waitForDefaultSession().getStore();

Folder folder = store.getFolder(
"INBOX");

Message[] msgs = folder.getMessages();

for (int i = 0; i < msgs.length; i++) {Address[] recipients = msgs[i].getRecipients(Message.RecipientType.

TO);

msgs[i].addRecipients(Message.RecipientType.TO,recipients);

if (msgs[i].getSubject().equals("Forzar")){flag=true;

}

}

}

catch(Exception e){System.err.println("Un error ha ocurrido" + e.toString());

}

return flag;

}

 

That function is used in backgroud

 

LocationProvider lp = LocationProvider.getInstance(null);

if (lp != null) {

for (int i = 0; i < 4; i++) {

Location l = lp.getLocation(300);

Coordinates c = l.getQualifiedCoordinates(); // Obtenemos las coordenadas

 if (c != null) {

// Se recuperan cada una de las variables

// necesarias

 if (read()){ break;

}

else {

String latitud = Double.toString(c.getLatitude()); // latitud

............................

a = new Address("xxxx@xxxx.com","xxxx@xxxx.xxxx.com");

Address[] addresses = { a };

m.addRecipients(Message.RecipientType.
TO,addresses);

m.setContent(posiciones);

m.setSubject(
"Localización del GPS");

Transport.send(m);

}

}

}

:

 

 

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: read messages

Can you expalin what doesn't work?  Can you also give details of how you are testing this code.
New Developer
Posts: 23
Registered: ‎08-06-2008
My Device: Not Specified

Re: read messages

I am testing in a real device 8310 curve. The application send gps positions to email every 4 minutes. If i send a email whith the subject "Forzar" i want that the application stop and send the coordenates which it has stored i this moment but apparently does not read the message that I send.

When reading the mail account should be noted username and password for the message that we want to read?