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
Regular Contributor
Posts: 75
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile
Accepted Solution

Attach file to email using mailto + Invokation Framework

I'm tryng to attach a file to an email using the mailto syntax.

The email app is opened by the Invocation framework

MailSubject = "Test"
MailBody = "Hello!";

// create handler invocation
navigator_invoke_invocation_t *invoke = NULL;
navigator_invoke_invocation_create(&invoke);

// setting the browser as target
navigator_invoke_invocation_set_target(invoke, "sys.pim.uib.email.hybridcomposer");

// set invocation action
navigator_invoke_invocation_set_action(invoke , "bb.action.OPEN, bb.action.SENDEMAIL");

// Setting URI
navigator_invoke_invocation_set_uri(invoke , ("mailto:pippo@pluto.it?cc=pluto@pippo.com&subject=" + MailSubject + "&body=" + MailBody + "&attachment=" + "file:///accounts/1000/shared/print/file").toAscii().data() );

// invoke the target
navigator_invoke_invocation_send(invoke);

// clean up resources
navigator_invoke_invocation_destroy(invoke);

 

I tried to remove file:/// and put / only but doesn't work either.
The file is in the shared folder and I know is the only way to attach a file to an emai.

 

https://developer.blackberry.com/native/documentation/core/email.html

 

Here there are some sample but none of them have precompiled field such cc + subject + body + attachment together.

Can anyone help me ?

Thanks

Regular Contributor
Posts: 75
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile

Re: Attach file to email using mailto + Invokation Framework

I would try to use the JSON format to prepopulate the email. However in the documentation here:

 

http://developer.blackberry.com/native/documentation/cascades/device_platform/invocation/email.html

 

it's not specified how to set the json data.

 

Should I pass it to the navigator_invoke_invocation_set_metadata function ?

BlackBerry Development Advisor
Posts: 249
Registered: ‎07-14-2008
My Device: Not Specified

Re: Attach file to email using mailto + Invokation Framework

That's correct. Use the JSON format and set it with navigator_invoke_invocation_set_data().
Highlighted
Regular Contributor
Posts: 75
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile

Re: Attach file to email using mailto + Invokation Framework

I tried to put this into a file:

{
  "to" : ["a@a.com", "b@b.net"],
  "from" : 1234,
  "cc" : ["foo@bar.com", "stuff@place.com"],
  "bcc" : ["foo@bar.com", "stuff@place.com"],
  "subject" : "Some punctuation. Symbol in the $ubject!!",
  "body" : "HI! Here is some more stuff.\n\n14% of emails have #1 newline or stuff* @ home.\n",
  "attachment" : ["file:///accounts/1000/shared/print/file"]
} 

 

And pass this content to the navigator_invoke_invocation_set_data() but it doesn't work. The email screen appear but none of the field are filled in.

Here is the code:

	navigator_invoke_invocation_t *invoke = NULL;
	navigator_invoke_invocation_create(&invoke);

	// setting the browser as target
	navigator_invoke_invocation_set_target(invoke, "sys.pim.uib.email.hybridcomposer");

	// set invocation action
	navigator_invoke_invocation_set_action(invoke ,  "bb.action.COMPOSE");

	navigator_invoke_invocation_set_type(invoke , "message/rfc822");

	navigator_invoke_invocation_set_data(invoke , JsonData.data() , JsonData.length() );

 




Regular Contributor
Posts: 75
Registered: ‎06-14-2013
My Device: Z10
My Carrier: PosteMobile

Re: Attach file to email using mailto + Invokation Framework

I switched from Json to QVariantMap and not it works without problems. Here is the code:

    bb::system::InvokeManager InvokeManager;
    bb::system::InvokeRequest InvokeRequest;

    QVariantMap EmailData;
    QVariantMap EmailDataWrapper;

    EmailData["to"] = "pippo@pluto.it";
    EmailData["cc"] = "paperino@topolino.it";
    EmailData["subject"] = "MailSubject";
    EmailData["body"] = "MailBody";
    EmailData["attachment"] =  "/accounts/1000/shared/print/file";

    EmailDataWrapper["data"] = EmailData;

    InvokeRequest.setTarget("sys.pim.uib.email.hybridcomposer");
    InvokeRequest.setAction("bb.action.COMPOSE");
    InvokeRequest.setMimeType("message/rfc822");
    InvokeRequest.setData(bb::PpsObject::encode(EmailDataWrapper , &bool_result) );

    InvokeManager.invoke(InvokeRequest);