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
aklowther
Posts: 47
Registered: ‎01-15-2013
My Device: Z10
My Carrier: N/A

Email won't send from within app

I believe I have everything laid out as it should be but I cannot get my email to send

 

void xxx::composeMessage(QString messageTo, QString messageSubject, QString messageBody)
{
	const MessageContact recipient = MessageContact(-1, MessageContact::To, QString(), "abc@xyz.com");
	const QByteArray bodyData = messageBody.toUtf8();

	MessageBuilder *builder = MessageBuilder::create(currentAccount.id());
	qDebug() << "Current: " << messageTo << messageSubject << bodyData;
	builder->subject("Test");
	builder->removeAllRecipients();
	builder->addRecipient(recipient);
	builder->body(MessageBody::Html, bodyData);

	// Send the new message via current account
	qDebug() << "Message1";
	messageService->send(currentAccount.id(), *builder);
	qDebug() << "Message2";

}

 

all private variables defined in .h file.

 

 

Any ideas what I'm missing?  This is the entire function, I pass the information from QML, using the qDebug() I am able to see that the function gets all the passed parameters and prints out "Message1" then the app crashes.  I have also checked the .pro and bar-descriptor and believe I have all necessary includes

Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Email won't send from within app

Why did you go with

MessageBuilder *builder 

instead of what we have in docs:

MessageBuilder builder;

in any case try changing

messageService->send(currentAccount.id(), *builder);

to

messageService->send(currentAccount.id(), &builder);
Please use plain text.
Developer
aklowther
Posts: 47
Registered: ‎01-15-2013
My Device: Z10
My Carrier: N/A

Re: Email won't send from within app

error: no matching function for call to 'bb::smileytongue:im::message::MessageService::send(bb::smileytongue:im::account::AccountKey, bb::smileytongue:im::message::MessageBuilder**)'
Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Email won't send from within app

sorry I meant

messageService->send(currentAccount.id(), builder);
Please use plain text.
Developer
aklowther
Posts: 47
Registered: ‎01-15-2013
My Device: Z10
My Carrier: N/A

Re: Email won't send from within app

same

error: no matching function for call to 'bb::pim::message::MessageService::send(bb::pim::account::AccountKey, bb::pim::message::MessageBuilder*&)'

 

Please use plain text.
Developer
Zmey
Posts: 1,512
Registered: ‎12-18-2012
My Device: PlayBook, Z10, DAC

Re: Email won't send from within app

In code from the first message try the following line:


messageService->send(currentAccount.id(), **builder);

 

If that won't work, try:

 

Message message = **builder;    /// or:  Message message = *builder;

messageService->send(currentAccount.id(), message);

 

You will need to delete the builder manually at the end of function, otherwise memory leak will occur:

delete builder;

 

I recommend creating the builder on stack like in example on this page so it will be destroyed automatically:

https://developer.blackberry.com/cascades/reference/bb__pim__message__messagebuilder.html

 


Andrey Fidrya, @zmeyc on twitter
Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Email won't send from within app

>I recommend creating the builder on stack like in example on this page so it will be destroyed automatically:

totally agree...

Please use plain text.
Developer
aklowther
Posts: 47
Registered: ‎01-15-2013
My Device: Z10
My Carrier: N/A

Re: Email won't send from within app

I originally tried that verbatim from the link you sent.

 

		MessageBuilder builder;// = MessageBuilder::create(currentAccount.id());
		qDebug() << "Current: " << messageTo << messageSubject << bodyData;
		builder.subject("Test");
		builder.removeAllRecipients();
		builder.addRecipient(recipient);
		builder.body(MessageBody::Html, bodyData);
		Message message = *builder;

		// Send the new message via current account
		qDebug() << "Message1";
		messageService->send(currentAccount.id(), message);
		qDebug() << "Message2";

 errors:

error: no matching function for call to 'bb::pim::message::MessageBuilder::MessageBuilder()'

error: no match for 'operator*' in '*builder'

 

Please use plain text.
Developer
BGmot
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Email won't send from within app

 

Message message = *builder;

Yes, this looks like an error.

May be:

Message message = (Message)builder;
Please use plain text.
Developer
aklowther
Posts: 47
Registered: ‎01-15-2013
My Device: Z10
My Carrier: N/A

Re: Email won't send from within app

thanks, though I'm still receiving the first error about no matching function
Please use plain text.