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

Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Email won't send from within app

[ Edited ]

It seems we were wrong, there's no public constructor in builder and the only way to create it is using create() method.



There's a working sample with MessageBuilder on github, have you seen it?



I think it leaks memory in composeMessage but at least it doesn't crash. Smiley Happy


Btw, is there any other info in crash report (NULL pointer reference etc)?

Can you please show how the messageService is declared and initialized?


Andrey Fidrya, @zmeyc on twitter
Posts: 47
Registered: ‎01-15-2013
My Device: Z10
My Carrier: N/A

Re: Email won't send from within app

I have seen it, wasn't able to replicate functionality. Oh well, thanks. I guess I'll invoke the email card for now
Posts: 16
Registered: ‎05-26-2013
My Device: Z10
My Carrier: UAE DU

Re: Email won't send from within app

Able to send the email from within the application, but when I add attachments the email is received without the attachment (see code snippet below). Any help???



void App::testEmailSending() {


// First, extract the corresponding provider account id to be used for sending email.


Account providerAccount = getProviderAccount();




// Second, build the corresponding message based on the providerAccount


MessageBuilder *message = getMessage(providerAccount);





// Third, use the message service, the provider account id, and the message to send.


MessageService *messageService = new MessageService(this);

if (messageService != NULL) {

messageService->send(providerAccount.id(), *message);







Account App::getProviderAccount() {


QList<bb:Smiley Tongueim::account::Account> accountList;


    // The current account

    bb:Smiley Tongueim::account::Account providerAccount;


    accountList = AccountService().accounts(Service::Messages);


    if(!accountList.isEmpty()) {

    // For now, we know they are 5 accounts, and we are only to get the one at id 3.

    if (accountList.length() >= 3) {

      providerAccount = accountList[3];




    return providerAccount;




MessageBuilder * App::getMessage(Account providerAccount) {


// Prepare the message to be sent.

MessageBuilder *builder = MessageBuilder::create(providerAccount.id());



QString subject = "Test Subject";

    MessageContact rto = MessageContact(-1,MessageContact::To,"Service" ,"test@gmail.com");


    QByteArray bodyData = "Testing email body";


    bool added;

    builder->addRecipient(rto, &added);

    builder->body(MessageBody::Html, bodyData);


// Let's also try to attach the uri file (the m_uri).

    // However, assuming this method is called after the invocation.

    QString xml;

    xml = "<?xml version=\"1.0\"?><TASKS><TASK><TASKID value=\"fcb5fa9e-ee5e-4fbc-a3fd-2d5f21e25608\"/></TASK></TASKS>";



    //Attachment attachment("application/xml", "xmlTaskFile", QUrl(m_uri));

    Attachment attachment("text/xml", "xmlTaskFile.xml", xml);



    QList<Attachment> attachments = builder->attachments();



    // Get the message in preparation to be used by the MessageService.


    return (builder);