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

Java Development

Reply
New Contributor
afishe2000
Posts: 4
Registered: ‎01-20-2011
My Device: Q10
My Carrier: AT&T

Message Status: Pending...

I'm writing a very simple program to send out an email.

 

The code was converted into eclipse plugin from the JDE 4.5.0.

 

It authors the email correctly and places it into the outbox but sits there "Pending".

 

Any help would be appreciated.

 

Thank you,

 

 

 

 

        public void SendEmail()
        {
            Store store = Session.getDefaultInstance().getStore();
            Folder[] folders = store.list(Folder.SENT);
            Folder sentfolder = folders[0];
            Message msg = new Message(sentfolder);
            Address toList[] = new Address[1];
            try 
            {
                toList[0]= new Address("xxx@gmail.com", "");
            } 
            catch(AddressException e) 
            {
                System.out.println(e.toString());
            } 
            try 
            {
                msg.addRecipients(Message.RecipientType.TO, toList);
                msg.setSubject(emailSubject);
            } 
                 catch(MessagingException e) {
            }
            try 
            {
                 Transport.send(msg);
                 System.exit(0);
            } 
            catch(MessagingException e) 
            {
                System.out.println(e.getMessage());
            }

 

 

 

 

Please use plain text.
Contributor
stkhan
Posts: 10
Registered: ‎06-16-2010
My Device: Curve 9300
My Carrier: Rogers

Re: Message Status: Pending...

I have been doing some similar debugging and found that if I remove the System.exit(0) the message sends. It creates another issue in that the application never exits, but the message does send.

Please use plain text.
Developer
simon_hain
Posts: 15,855
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: Message Status: Pending...

maybe you can use a sendlistener and exit the app when the message is sent.
or use a thread to let the app sleep some time after sending and exit it then.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
stkhan
Posts: 10
Registered: ‎06-16-2010
My Device: Curve 9300
My Carrier: Rogers

Re: Message Status: Pending...

I tried Simons thread example and it works.  I did not use the system.exit by using a thread to send the e-mail, when the thread completes it seems to exit automatically (I think it is supposed to).

When I put the system.exit after I send the message the message doesn't actually send;

 

Transport.send(emailmessage);

System.exit(0); //this seems to prevent the email from sending

 

Without the System.exit(0) the message gets sent and the thread closes.

 

Thanks Simon.

Please use plain text.