在黑莓中发送邮件

时间:2010-03-10 07:15:22

标签: email duplicates blackberry-eclipse-plugin

我想创建一个可以在黑莓中发送电子邮件的应用程序。我可以有一个示例代码或教程

非常感谢

2 个答案:

答案 0 :(得分:2)

您可以使用API​​直接或以编程方式发送两种类型的电子邮件

public void sendemail(String s){
        Message m = new Message();
        Address a = null;
        try
        {
            a = new Address("","");
        } catch (AddressException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        Address[] addresses = {a};
        try
        {
            m.addRecipients(net.rim.blackberry.api.mail.Message.RecipientType.TO, addresses);
            m.setContent(s);
        } catch (MessagingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        m.setSubject(" My Croxley ");
        Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(m));
    }

另一种方式

public boolean SendEmail(String emailFrom, String emailTo, String subject, String messageData, String fileName, byte[] fileData)
{
        // create a multipart message
        Multipart mp = new Multipart();
        TextBodyPart tbp = new TextBodyPart(mp, messageData);
        mp.addBodyPart(tbp);

        SupportedAttachmentPart sap = new SupportedAttachmentPart(mp, "audio/amr", fileName, fileData);
        mp.addBodyPart(sap);

        // create a message in the sent items folder
       Folder folders[] = Session.getDefaultInstance().getStore().list(Folder.SENT);
       Message message = new Message(folders[0]);

       // add recipients to the message and send
       try 
       {
           Address toAdd = new Address(emailTo, emailTo);
           Address toAdds[] = new Address[1];
           toAdds[0] = toAdd;
           message.addRecipients(Message.RecipientType.TO, toAdds);
           message.setSubject(subject);
           message.setContent(mp);
           //sets priority
           //message.setPriority(Message.Priority.HIGH);
           net.rim.blackberry.api.mail.Transport.send(message);
           return true;
       } 
       catch (Exception e) 
       {
            return false;
       }
    }

答案 1 :(得分:0)