Blackberry - problem in sending mail
While trying to send mail I've received error:
sendingfailedexception:MAIL_API:no rim service record
Code:
try
{
Session s = Session.getDefaultInstance();
if(s == null)
{
String errMsg = "Unabled to send email message.\n";
Dialog.alert(errMsg);
bCanSend = false;
}
else
{
bCanSend = true;
_emailTo =" poomalai@i-waves.com";
_emailBody = "emailBody";
emailTransport = Session.getTransport();
// msgStore = Session.waitForDefaultSession().getStore();
// folderList = msgStore.list(Folder.SENT);
// outFolder = folderList[0];
// msg = new Message(outFolder);
msg = new Message();
}
}
catch(Exception nse)
{
System.out.println(nse.toString());
}
try
{
System.out.println("SendEmail :: running");
if(bCanSend == true)
{
Address [] addresses = new Address[1];
addresses[0] = new Address(_emailTo, _emailTo);
msg.addRecipients(Message.RecipientType.TO, addresses);
开发者_StackOverflow msg.setSubject("IBM Calendar Share!");
msg.setContent(_emailBody);
}
}
catch(Exception e)
{
System.out.println("Exception caught trying to send email: " +
e.toString());
Dialog.inform(e.toString());
}
try
{
emailTransport.send(msg);
}
catch(Exception e)
{
System.out.println("Exception caught trying to send email: " +
e.toString());
Dialog.inform(e.toString());
}
I get this error on devices which have no email account setup on them. e.g. there is a data connection, a BBM connection, and the guy uses gmail - but does has not configured an email account in the OS.
I also call
Session emailSession = Session.getDefaultInstance();
This does not return null
- so looking at your code, you assumed you can send. But the call to Transport.send(msg)
fails because the account is not setup.
Edit: I have read that this error can also come up if you try to set the "from" address to an invalid account.
Catch this exception (like you have) and tell the user to set up a valid email account before retrying.
You can't send mail from the simulator.
精彩评论