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: 47
Registered: ‎01-15-2013
My Device: Z10

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

Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

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);
Developer
Posts: 47
Registered: ‎01-15-2013
My Device: Z10

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**)'
Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: Email won't send from within app

sorry I meant

messageService->send(currentAccount.id(), builder);
Developer
Posts: 47
Registered: ‎01-15-2013
My Device: Z10

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*&)'

 

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

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
Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

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...

Developer
Posts: 47
Registered: ‎01-15-2013
My Device: Z10

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'

 

Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook

Re: Email won't send from within app

 

Message message = *builder;

Yes, this looks like an error.

May be:

Message message = (Message)builder;
Developer
Posts: 47
Registered: ‎01-15-2013
My Device: Z10

Re: Email won't send from within app

thanks, though I'm still receiving the first error about no matching function