BB 10 Cascades qml sending a simple email
Asked Answered
A

2

5

I found one example in the the git hub for BB 10 for sending an email, but it looks pretty complicated and alot done in C.

does anyone have an example on how to send a quick email using QML. I don't need any buttons or text fields, just hard coded values.

I found this simple snip, but dont' know how to integrate it.

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

Any help would be appreciated.

Ankeny answered 29/1, 2013 at 21:38 Comment(3)
Do you want to do it from within QML? As an invocation on a card?Parliamentary
yes, i would like to do it from QML if possible. I would just to like to use hard coded vales such as email, subject etc for just now. developer.blackberry.com/cascades/documentation/device_platform/… this link seems to do what i want, it looks to be C, but i can work with simple C.Ankeny
Are you trying to programatically send and email without the user's intervention, or would it be something that the user would want to confirm before actually sending? It's pretty trivial to do the latter, and most of the time the user should get some confirmation option.Citron
D
7

Following code will open a sheet with email composer having all the specified email fields prepopulated:

import bb.cascades 1.0

Page {
    Container {
        horizontalAlignment: HorizontalAlignment.Fill
        layout: DockLayout {
        }

        Container {
            horizontalAlignment: HorizontalAlignment.Center
            verticalAlignment: VerticalAlignment.Center
            TextArea {
                id: emailBody
            }
            Button {
                text: "Send email"
                onClicked: {
                    emailInvocation.query.uri = "mailto:[email protected]?subject=Test&body=" + emailBody.text
                    emailInvocation.query.updateQuery();
                }
            }
        }
    }

    attachedObjects: [
        Invocation {
            id: emailInvocation
            query.mimeType: "text/plain"
            query.invokeTargetId: "sys.pim.uib.email.hybridcomposer"
            query.invokeActionId: "bb.action.SENDEMAIL"
            onArmed: {
                emailInvocation.trigger(emailInvocation.query.invokeActionId);
            }
        }
    ]
}
Distil answered 11/7, 2013 at 5:57 Comment(0)
S
0

In main.cpp after creating your QmlDocument, qml->setContextProperty("yourshortcut", object);

void xxx::invokeEmail(){
InvokeManager invokeManager;
InvokeRequest request;
request.setTarget("sys.pim.uib.email.hybridcomposer");
request.setAction("bb.action.COMPOSE");
request.setMimeType("message/rfc822");

InvokeTargetReply *reply = invokeManager.invoke(request);
if(reply) {
    reply->setParent(this);
    QObject::connect(reply, SIGNAL(finished()),this, SLOT(onInvokeResult()));
    _invokeTargetReply = reply;
}
delete reply;
}

void xxx::onInvokeResult()
{
// Check for errors
switch(_invokeTargetReply->error()) {
// Invocation could not find the target
// did we use the right target ID?
case InvokeReplyError::NoTarget: {
    qDebug() << "invokeFinished(): Error: no target" << endl;
    break;
}
// There was a problem with the invoke request
// did we set all the values correctly?
case InvokeReplyError::BadRequest: {
    qDebug() << "invokeFinished(): Error: bad request" << endl;
    break;
}
// Something went completely
// wrong inside the invocation request
// Find an alternate route :(
case InvokeReplyError::Internal: {
    qDebug() << "invokeFinished(): Error: internal" << endl;
    break;
}
//Message received if the invoke request is successful
default:
    qDebug() << "invokeFinished(): Invoke Succeeded" << endl;
    break;
}

// A little house keeping never hurts...
delete _invokeTargetReply;
}

Then in QML call the C++ function invokeEmail using the shortcut you created with the context property. I use this to invoke the email card

Scribbler answered 7/2, 2013 at 19:46 Comment(2)
This doesn't cover populating the to field or the content, it just invokes the email compose card... it requires building the message up as JSON - not managed to do it myself either though.Waftage
you can change the target/action/mime/etc info to match linkScribbler

© 2022 - 2024 — McMap. All rights reserved.