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
Regular Contributor
Posts: 77
Registered: ‎02-17-2010
My Device: Not Specified
Accepted Solution

deleting mails

[ Edited ]

hi,

 

please help me to resolve this problem.... 

 

this is the code am using to send mails. after that am deleting that mail. to send mails to 10 users, am calling this function inside a loop passing the mail address as parameter.but it wil send mail only to first mailid. after that its not sending mail. am not getting where exactly the problem is....

 

help me ..

 

 

public void SendMail1(String smailid,String content,String subj)
	{
	
		try {
			
			ServiceBook sb = ServiceBook.getSB(); 
			ServiceRecord[] srs = sb.findRecordsByCid("CMIME"); 
			if (srs != null)
			{
				  for (int i = srs.length -1; i >= 0; --i) 
				  {
				        ServiceRecord sr = srs[i];
				        
				       try {
	

	                        ServiceConfiguration sc = new ServiceConfiguration(sr); 
				            Session session = Session.getDefaultInstance(sc); 
				            Store    store = session.getStore();
				        	Folder[]      folders = store.list(Folder.SENT); 
				          Folder       sentfolder = folders[0]; 				            
				        	Message    msg = new Message(sentfolder); 
				            recipients = new Address[1]; 
				            //String 
				            recipients[0]= new Address(smailid, "user");
					        
						     //add the recipient list to the message
						     msg.addRecipients(Message.RecipientType.TO, recipients);

						     //set a subject for the message
						     msg.setSubject(subj+"|"+pin);

						     //sets the body of the message
						     msg.setContent(content);						    
						     snd=smailid;
						     //send the message
						    
						 Transport.send(msg);
						    
						    
			//deleting mails after sending 
						 sentfolder.deleteMessage(msg,true);
				           
				       }
				       catch(Exception ex)
				       {
				    	   
				       }
				  }
				       
			}
		
			else
			{
				
				System.exit(0);
			}
		}
		catch(Exception ex)
		{
			
		}		


		
	}	

this is the loop

 

for(int i=0;i<vecsendmail.size();i++)
		{
	//vector which holds all mail ids		
String pstatus=vecsendst.elementAt(i).toString();
			sdmail.SendMail1(pmailid, pcontent, psubj+pstatus);
			
		}

 

 

 

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: deleting mails

Please use the Insert Code button (clipboard with C on it in the post message screen) when posting code.

 

The code you have posted is very hard to read. Thanks.

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Regular Contributor
Posts: 77
Registered: ‎02-17-2010
My Device: Not Specified

Re: deleting mails

hi,,,

 

am sorry... not i edited it and posted it again..

 

waiting for reply....

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: deleting mails

[ Edited ]

You should probably add a MessageListener to the message to make sure it sends before you delete it or it might not even send.

 

 

Transport.send(msg);

msg.addMessageListener(new MessageListener(){
public void changed(MessageEvent e) {
Message theMsg = e.getMessage();

if( Message.Status.TX_SENT == theMsg.getStatus() || Message.Status.TX_DELIVERED == theMsg.getStatus() ) {
theMsg.getFolder().deleteMessage(theMsg, true);
}
}
});

Are you getting any errors? I notice in your try...catch you're not printing your stack trace or printing the error message.

 

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful
Regular Contributor
Posts: 77
Registered: ‎02-17-2010
My Device: Not Specified

Re: deleting mails

hi,

 

no am not getting any error..

if i remove this code  "sentfolder.deleteMessage(msg,true)"  from sendmail() function, everything works fine. it sends mail to all....

Developer
Posts: 1,055
Registered: ‎01-25-2009
My Device: BlackBerry Bold 9650/BlackBerry Torch 9800

Re: deleting mails

By using the code I've posted above, it should work fine too. Your issue must've been that you were deleting them before they were sent.

Jerome Carty - Follow jcarty on Twitter@jcarty | #webworks-dev / #BlackberryDev on irc.freenode.net | My Apps
Click "Accept as Solution" if post solved your original issue.. Give like/thumbs up if you feel post is helpful