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
Posts: 579
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA
Accepted Solution

How to send an email from a BB10 app?

[ Edited ]

https://developer.blackberry.com/native/documentation/cascades/device_platform/pim/messages.html

 

This describes code examples like:

 

// Create the message service object
MessageService service;
 
// Create the recipients for the first message
MessageContact firstRecipient = MessageContact(1, MessageContact::To,
        "Wes Barichak", "wes.barichak@example.com");
MessageContact secondRecipient = MessageContact(2, MessageContact::To,
        "Karla Tetzel", "karla.tetzel@example.com");
MessageContact thirdRecipient = MessageContact(3, MessageContact::Cc,
        "Mike Chepesky", "mike.chepesky@example.com");
 
// Create the first message
MessageBuilder msg1Builder;
Message firstMessage = msg1Builder.subject("Lunch")
        .body(MessageBody::smileytongue:lainText, QByteArray("Got lunch plans? Let
                                      me know and we'll go somewhere!"))
        .addRecipient(firstRecipient)
        .addRecipient(secondRecipient)
        .addRecipient(thirdRecipient);
 
... but there is no way to make a MessageBuilder object like that. It seems to require an AccountKey object:
 
 
Is it possible that the documentation is horribly out of date?!
Developer
Posts: 579
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: Messages Documention Out of Date?

After searching these forums I think I've implicitly confirmed that the code sample on BB's documentation page doesn't work, which blows my mind for something like sending an email.

 

I'm trying:

 

    bb::pim::account::AccountService accountService;
    bb::pim::account::Account defaultClient = accountService.defaultAccount(bb::pim::account::Service::Messages);
    bb::pim::account::AccountKey accountId = defaultClient.id();

    // Create the message service object
    MessageService service;

    // Create the recipients for the first message
    MessageContact firstRecipient = MessageContact(1, MessageContact::To,
            "Daniel Bigham", "daniel.bigham@gmail.com");

    // Create the first message
    MessageBuilder* msg1Builder = MessageBuilder::create(accountId);
    Message firstMessage =
            msg1Builder->subject("Photos for you")
            .body(MessageBody::PlainText, QByteArray(""))
            .addRecipient(firstRecipient);

    // Send the first message using the message service object
    service.send(1, firstMessage);

 

... but when I execute the code, I get the following printed in the console:

 

Exception String "The RPC service Account:1 has no message_send command"
ErrorInfo MessageServicePrivate::handleResponse The RPC service Account:1 has no message_send command : 500 methodid EMS::send
PIMCoreAccessPool::returnPca 1

 

Does anyone out there have a working example of how to send an email message from a BB10 Cascades app?

Developer
Posts: 579
Registered: ‎04-01-2009
My Device: Z10, PlayBook
My Carrier: NA

Re: Messages Documention Out of Date?

I realized that I hadn't checked the sample apps, and there is in fact a "messages" sample app that appears to work.