从Blackberry java开发发送电子邮件

时间:2012-03-05 14:44:03

标签: blackberry-eclipse-plugin blackberry-jde

我对从Blackberry java开发中发送电子邮件有疑问。

我的应用程序正确发送邮件,但它默认为从以前配置的BlackBerry设备上的邮件,我不知道如何将标题FROM替换为另外的电子邮件,例如Blackberry设备中配置的电子邮件,我把我的代码如下:

try { 

      Address()  ad = new Address ("emailexample@hotmail.com", "Maria Gomez");

     } Catch (AddressException e) {


try {

 Store store = Session.getDefaultInstance().getStore ();

 Folder [] folders = store.list (Folder.SENT);
 Sentfolder folder = folders [0];

 msg = new Message (sentfolder);


try {

 String [] v = splitString (toField.getText (), ',', false);
           toList = new Address [v.length];

    for (int i = 0; i <v.length i + +)
          {
             toList [i] = new Address (v [i], "");
           }

        } Catch (AddressException e) {System.out.println (e.toString ());}

msg.addRecipients (Message.RecipientType.TO, toList);
msg.setSubject (subjectField.getText ());
msg.setContent (msgField.getText ());
msg.setFrom (ad);

if (toField.getText().compareTo("") == 0 | | fromField.getText().compareTo("")==0)
{
Dialog.alert ("ERROR: \ n Lack mail recipient \ no sender");
}
else
{
Transport.send (msg);
Dialog.alert ("the mail was sent");
subjectField.setText ("");
msgField.setText ("");
}

} Catch (MessagingException e) {
System.out.println (e.getMessage ());
Dialog.alert ("No mail was sent");
}

我尝试使用msg.setFrom(ad),但是没有用,然后我尝试使用msg.setHeader(“FROM”,“emailexample@gmail.com”)这两项工作都没有。

等待帮助,谢谢。

1 个答案:

答案 0 :(得分:1)

嗨试试这个工作正常,

public void TextMailSend() 
        {           

            String htmlContent =  " Name:"+Name+ "\n Common Name:"+cmn_nm +"\n Radious:"+radius+"\n Year:"+yr+"\n Latitude:"+lat +"\n Longitude :"+lng ;

            Message msg = new Message(); 
            try 
            { 
                final Address address = new Address("",""); 
                Address[] addresses = {address}; 
                msg.addRecipients(net.rim.blackberry.api.mail.Message.RecipientType.TO, addresses); 
                msg.setContent(htmlContent); 
                msg.setSubject("Subject"); 

                Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES, new MessageArguments(msg));
                //Dialog.inform("Mail send fully.");
            } 
            catch (AddressException e) 
            { 
                e.printStackTrace(); 
                System.out.println("AddressException -->"+e.getMessage()); 
            } 
            catch (MessagingException e) 
            { 
                e.printStackTrace(); 
                System.out.println("MessagingException -->"+e.getMessage()); 
            }
        }