Search in sources :

Example 1 with Address

use of net.rim.blackberry.api.mail.Address in project CodenameOne by codenameone.

the class BlackBerryImplementation method sendMessage.

public void sendMessage(String[] recipients, String subject, Message msg) {
    Folder[] folders = Session.getDefaultInstance().getStore().list(Folder.SENT);
    net.rim.blackberry.api.mail.Message message = new net.rim.blackberry.api.mail.Message(folders[0]);
    try {
        Address[] toAdds = new Address[recipients.length];
        for (int i = 0; i < recipients.length; i++) {
            Address address = new Address(recipients[i], "");
            toAdds[i] = address;
        }
        message.addRecipients(net.rim.blackberry.api.mail.Message.RecipientType.TO, toAdds);
        message.setSubject(subject);
    } catch (Exception e) {
        EventLog.getInstance().logErrorEvent("err " + e.getMessage());
    }
    try {
        if (msg.getAttachment() != null && msg.getAttachment().length() > 0) {
            Multipart content = new Multipart();
            TextBodyPart tbp = new TextBodyPart(content, msg.getContent());
            content.addBodyPart(tbp);
            InputStream stream = com.codename1.io.FileSystemStorage.getInstance().openInputStream(msg.getAttachment());
            byte[] buf;
            buf = IOUtilities.streamToBytes(stream);
            stream.close();
            String name = msg.getAttachment();
            name = name.substring(name.lastIndexOf(getFileSystemSeparator()) + 1, name.length());
            SupportedAttachmentPart sap = new SupportedAttachmentPart(content, msg.getAttachmentMimeType(), name, buf);
            content.addBodyPart(sap);
            message.setContent(content);
        } else {
            message.setContent(msg.getContent());
        }
        app.setWaitingForReply(true);
        Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(message));
    } catch (Exception ex) {
        EventLog.getInstance().logErrorEvent("err " + ex.getMessage());
    }
}
Also used : Multipart(net.rim.blackberry.api.mail.Multipart) TextMessage(javax.wireless.messaging.TextMessage) Message(com.codename1.messaging.Message) Address(net.rim.blackberry.api.mail.Address) BufferedInputStream(com.codename1.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DataInputStream(java.io.DataInputStream) InputStream(java.io.InputStream) TextBodyPart(net.rim.blackberry.api.mail.TextBodyPart) Folder(net.rim.blackberry.api.mail.Folder) IOException(java.io.IOException) RecordStoreException(javax.microedition.rms.RecordStoreException) MediaException(javax.microedition.media.MediaException) ConnectionNotFoundException(javax.microedition.io.ConnectionNotFoundException) MessageArguments(net.rim.blackberry.api.invoke.MessageArguments) SupportedAttachmentPart(net.rim.blackberry.api.mail.SupportedAttachmentPart)

Aggregations

BufferedInputStream (com.codename1.io.BufferedInputStream)1 Message (com.codename1.messaging.Message)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ConnectionNotFoundException (javax.microedition.io.ConnectionNotFoundException)1 MediaException (javax.microedition.media.MediaException)1 RecordStoreException (javax.microedition.rms.RecordStoreException)1 TextMessage (javax.wireless.messaging.TextMessage)1 MessageArguments (net.rim.blackberry.api.invoke.MessageArguments)1 Address (net.rim.blackberry.api.mail.Address)1 Folder (net.rim.blackberry.api.mail.Folder)1 Multipart (net.rim.blackberry.api.mail.Multipart)1 SupportedAttachmentPart (net.rim.blackberry.api.mail.SupportedAttachmentPart)1 TextBodyPart (net.rim.blackberry.api.mail.TextBodyPart)1