2011-10-28 8 views
-1

プログラムで電子メールを送信したいと思います。そのために、私は以下のコードを書いた:Blackberryでプログラムで電子メールを送信するには?

if(field == m_btnSend) 
    { 
     Store store = Session.getDefaultInstance().getStore(); 
     Folder[] folder = store.list(Folder.SENT); 
     Folder sent = folder[0]; 

     Message msg = new Message(sent); 
     Address receipent[] = new Address[1]; 
     try 
     { 
      receipent[0] = new Address("[email protected]", "Arindam"); 

      msg.addRecipients(Message.RecipientType.TO, receipent); 

      msg.setSubject("Test Mail"); 

      msg.setContent("This mail is to remind you that programmatically we can send the mail"); 

      msg.setPriority(Priority.HIGH); 

      Transport.send(msg); 

     } 

     catch (Exception e) 
     { 
      e.printStackTrace(); 
     } 
    } 

私はMDSシミュレータで実行しています。今私はシミュレータのブラウザでメールを開くと、このメールをメールインボックスで見たいと思っています。それはどのように可能ですか?

ありがとうございました。

答えて

0

これは、メールで添付ファイルを送信するためのコードであり、それは、デバイス上で非常にうまく機能:

private void sendmail() 
{ 
try 
{ 
Address[] address = new Address[1]; 
address[0] = new Address(" "," "); 
Folder folders[] = Session.getDefaultInstance().getStore().list(Folder.SENT); 
msg=new Message(folders[0]); 
msg.addRecipients(Message.RecipientType.TO, address); 
msg.setSubject(" "); 
SupportedAttachmentPart attach = new   SupportedAttachmentPart(multipart,"application/pdf",pdfName,data); 
multipart.addBodyPart(attach); 
msg.setContent(multipart); 
Invoke.invokeApplication(Invoke.APP_TYPE_MESSAGES,new MessageArguments(msg)); 

try 
{ 
Transport.send(msg); 
} 
catch(SendFailedException e) 
{ 
    System.out.println("messages for sent : : : : : : "+e.getMessage()); 
    } 

} 
0

私のサイトで以下のコードを確認してください。 sending-email-with-attachment-in Blackberry

+0

ねえ、私はcode..iが既にを示しています。そして、それは正常に動作しています。しかし、どうすれば私のメールでそれを得ることができますか? –

+0

あなたはどういう意味ですか?しかし、どうすれば私のメールでそれを得ることができますか?あなたはデバイスでテストしたいですか? –

+0

私はデバイスでテストしたくありません。私はBlackBerry EmailとMDS Servicesシミュレータ4.1.2を使用しています。 ESSシミュレーターでは、パスワードとユーザー名を要求しています。私は取得していない、私はそこに与える必要がある資格情報は何ですか。 –

0

まずモーション検出ですべてのプログラム> Reasearch>スタート - からブラックベリーJDEのシミュレータでコードを実行した後thisを読む> MDSは、その後、6まで、このdocumentation .doという手順を読んで選択し、あなたのメールがあなたのプログラムを経由して送信され表示されますメッセージフォルダのアプリケーション パスワードとユーザー名を入力する必要はありません

0

このコードを試す - 電子メールを送信するには、BISがデバイスでアクティブになっている必要があります。シミュレータでは機能しません。また、デバイスに電子メールが設定されています。

      try 
          { 
          recipients[0]= new Address(id_,name_); 

          //add the recipient list to the message 
          msg.addRecipients(Message.RecipientType.TO, recipients); 

          //set a subject for the message 
          msg.setSubject("Test email"); 

          //sets the body of the message 
          msg.setContent("123456789---------------"); 

          //sets priority 
          msg.setPriority(Message.Priority.HIGH); 

          //send the message 
          Transport.send(msg); 
         } 

         catch (Exception me) 
         { 
          Dialog.alert(me+""); 
          System.err.print(me); 
         }