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 Developer
PeteBarkley
Posts: 19
Registered: ‎07-14-2008
My Device: Not Specified

Send email to Self/Place email in Inbox

[ Edited ]

Hello, I am using the following code to try and place an email in the user's inbox.

    public void sendEmail()
    {
        String emailAddress = getEmailAddress();
        
        if(emailAddress != null)
        {
            statusFielder.setText(statusFielder.getText() +"\n" +"My email: " +emailAddress);
            //Get the Store from the default mail Session.
            Store store = Session.getDefaultInstance().getStore();

            Folder[] folders = store.list(Folder.INBOX);
            Folder inbox = folders[0];

            Message msg = new Message(inbox);
            Address to[] = new Address[2];

            try {
                to[0]= new Address("Update", "Update"); 
                to[1] = new Address(emailAddress, emailAddress);
                
                msg.setFrom(to[0]);
                msg.addRecipient(Message.RecipientType.TO, to[1]);
                msg.setSubject("Certificate Expiry");

                msg.setContent("Hello, \n Your certificate is aboot to expire");

                msg.setPriority(Message.Priority.HIGH);
                
                msg.setInbound(true);
                
                msg.setStatus(Message.Status.RX_RECEIVED, Message.Status.TX_SENT);
                
                //send the message
                net.rim.blackberry.api.mail.Transport.send(msg);
            }
            catch (Exception me) {
               statusFielder.setText(me.toString());
            }
        }
        else
        {
            statusFielder.setText("No Default Email");
        }
    }
    
     public static String getEmailAddress() 
     {
        String emailAddress;
        try {
            Session ourSession = Session.getDefaultInstance();
     
            emailAddress = ourSession.getServiceConfiguration().getEmailAddress();
        } catch ( Exception e ) {
            emailAddress = null;
        }
        return emailAddress;
    }

However this places it in the Outbox as if it were waiting to be sent. How can I make it so it goes to the Inbox instead of Outbox? (Have only tested on simulator)

 

Thanks

Please use plain text.
Administrator
MSohm
Posts: 14,437
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
My Carrier: Bell

Re: Send email to Self/Place email in Inbox

This should be stored in the Inbox, but it will be a draft message that is ready to be sent.

 

If you wish to add a custom (non draft) message to the inbox you can use the MessageList APIs.  You can refer to the messagelistdemo that comes with the BlackBerry Java SDK and BlackBerry JDE for an example.

 

Documentation on this can be found here: http://docs.blackberry.com/en/developers/deliverables/7693/Using_custom_messages_folders_511381_11.j...

 

 

 

Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Found a bug? Report it using Issue Tracker
Please use plain text.