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

Native Development

Reply
Developer
Developer
Posts: 24
Registered: ‎05-14-2014
My Device: Blackberry-Z10
My Carrier: Vodafone
Accepted Solution

Reading,replying, deleting messages from Message Hub without user interaction

I need to access the Message hub to read email/messages from particular sender.  The app would read the message, extract information like sender email address from the message and reply to sender. I want to achieve this without the user interaction or interference for automatic testing purpose.

 

For example, I receive a message in the Blackberry hub, the Application searches and read the message from specific sender. It then extract information and replies back to the sender. After sending the reply the message needs to be deleted. But this should happen as soon as the Application is started. So there is no user interference everything in coded in src files.

 

There is sample app PIM Message which does something similar. But there is user interaction necessary to send message. I did some minor changes and hardcode an email address. It does send an email to that address but I need to touch 'Send' button. I wish to do that as soon as the application is started without interacting with GUI for testing purpose.

 

Is it possible to do this in the background and GUI only displays information such as email/message received, reply sent?

 

I have read the reference for MessageService, Message etc. at the http://developer.blackberry.com/native/reference/cascades for information about API.

Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Reading,replying, deleting messages from Message Hub without user interaction

No.


If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Reading,replying, deleting messages from Message Hub without user interaction

Actually, you can. In the Messages example, the "send" functionality is attached to a button so you can trigger it yourself when playing around with the app, but really you as a developer could haved called it at any point.. This is they key function:

 

void MessageComposer::composeMessage()
{
    const MessageContact recipient = MessageContact(-1, MessageContact::To, QString(), m_recipient);
    const QByteArray bodyData = m_body.toUtf8();

    // Create a message builder to create/modify the message
    MessageBuilder *builder = (m_mode == CreateMode ? MessageBuilder::create(m_accountId)
                                                    : MessageBuilder::create(m_accountId, m_messageService->message(m_accountId, m_messageId)));

    builder->subject(m_subject);
    builder->removeAllRecipients();
    builder->addRecipient(recipient);
    builder->body(MessageBody::PlainText, bodyData);

    // Send the new message via current account
    m_messageService->send(m_accountId, *builder);
}

 

However, this does require the access_pimdomain_messages permission, which most users will not give you unless you have a pretty good justification (as it lets you do stuff like this).

 

What you can't do is use the email composer card without the user's interaction, which is how you would normally want to send an email. Doing that doesn't require the messages permission, as the user has full control over what (if anything) gets sent.

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Reading,replying, deleting messages from Message Hub without user interaction

Hi Paul,

Isn't this just composing the message?
Can you really, in the background, scan all the mail for a particular user and, extract the sender info and then auto send a reply?

If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.
Retired
Posts: 749
Registered: ‎12-16-2008
My Device: BlackBerry Z30
My Carrier: Bell

Re: Reading,replying, deleting messages from Message Hub without user interaction

You could use MessageService::searchLocal to retrieve all messages from a sender, and can connect to the MessageService::messageAdded signal to get notified whenever a new message comes in. One you have a Message, you can get all sorts of information.

 

The PIM APIs are actually very powerful, they're designed to support enterprise users in regulated environments where you legally need all sorts of tracking and safeguards and such.

Paul Bernhardt
Application Development Consultant
BlackBerry
@PBernhardt

Did this answer your question? Please accept this post as the solution.
Found a bug? Report it to the Developer Issue Tracker
Developer
Posts: 6,152
Registered: ‎07-05-2012
My Device: Playbook, Dev Alpha C, Z10 LE, Z30
My Carrier: Orange

Re: Reading,replying, deleting messages from Message Hub without user interaction

Okay I've learned something new, thanks.

If you've been helped click on Like Button, if you've been saved buy the app. Smiley Happy

Developer of stokLocker, Sympatico and Super Sentences.