Difference between revisions of "Teams Winter 2011/team1/BlackBerry/Add Send Email Option"

From CDOT Wiki
Jump to: navigation, search
(Created page with '== Adding Send Email Functionality == 9.1 Lets first add the api which we will need for the email functionality <pre> import net.rim.blackberry.api.mail; </pre> 9.2 In order …')
 
Line 2: Line 2:
  
 
9.1 Lets first add the api which we will need for the email functionality
 
9.1 Lets first add the api which we will need for the email functionality
<pre>
+
<source lang="java">
 
   import net.rim.blackberry.api.mail;
 
   import net.rim.blackberry.api.mail;
</pre>
+
</source>
  
 
9.2 In order to add send email functionality to our application, we must have the appropriate menu option in our application.
 
9.2 In order to add send email functionality to our application, we must have the appropriate menu option in our application.
  
<pre>
+
<source lang="java">
 
// Email selected student
 
// Email selected student
 
MenuItem emailStudent = new MenuItem(new StringProvider("Email Student"), 500, 5);
 
MenuItem emailStudent = new MenuItem(new StringProvider("Email Student"), 500, 5);
Line 20: Line 20:
 
));
 
));
  
</pre>
+
</source>
  
 
9.3 Now lets get the students email address and name
 
9.3 Now lets get the students email address and name
<pre>
+
<source lang="java">
 
   Student student = (Student) _keywordFilterField.getSelectedElement();
 
   Student student = (Student) _keywordFilterField.getSelectedElement();
 
   String studentEmail = student.getEmail();
 
   String studentEmail = student.getEmail();
 
   String studentName = student.getname();
 
   String studentName = student.getname();
</pre>
+
</source>
  
 
9.4 Now we must set up a new message and content. Here we create a new message in the SENT folder of the device and fill it with a predefined body
 
9.4 Now we must set up a new message and content. Here we create a new message in the SENT folder of the device and fill it with a predefined body
<pre>
+
<source lang="java">
 
   Store store = Session.getDefaultInstance().getStore();
 
   Store store = Session.getDefaultInstance().getStore();
 
   Folder sentFolder = store.list(Folder.SENT);
 
   Folder sentFolder = store.list(Folder.SENT);
Line 48: Line 48:
 
   //send the message
 
   //send the message
 
   Transport.send(msg);
 
   Transport.send(msg);
</pre>
+
</source>
  
 
9.5 Lets catch any exceptions and notify the user if the message was sent.
 
9.5 Lets catch any exceptions and notify the user if the message was sent.
<pre>
+
<source lang="java">
 
   catch (Exception me) {
 
   catch (Exception me) {
 
     System.err.println(me);
 
     System.err.println(me);
Line 57: Line 57:
 
                  
 
                  
 
   Dialog.alert(studentName + " has been emailed!");
 
   Dialog.alert(studentName + " has been emailed!");
</pre>
+
</source>

Revision as of 12:31, 28 March 2011

Adding Send Email Functionality

9.1 Lets first add the api which we will need for the email functionality

  import net.rim.blackberry.api.mail;

9.2 In order to add send email functionality to our application, we must have the appropriate menu option in our application.

// Email selected student
MenuItem emailStudent = new MenuItem(new StringProvider("Email Student"), 500, 5);
editItem.setCommand(new Command(new CommandHandler(){

public void execute(ReadOnlyCommandMetadata metadata, Object context) {
// TODO Auto-generated method stub

}
}
));

9.3 Now lets get the students email address and name

  Student student = (Student) _keywordFilterField.getSelectedElement();
  String studentEmail = student.getEmail();
  String studentName = student.getname();

9.4 Now we must set up a new message and content. Here we create a new message in the SENT folder of the device and fill it with a predefined body

  Store store = Session.getDefaultInstance().getStore();
  Folder sentFolder = store.list(Folder.SENT);
  Message msg = new Message(sentFolder);
                   
                      
  // Set up recipients
  Address recipients = new Address(studentEmail, studentName);
  //Add the recipient to the message
  msg.addRecipients(Message.RecipientType.TO, recipients);
  //set a subject for the message
  msg.setSubject(“Team 1 test email”);
  //sets the body of the message
  msg.setContent(“This is a test email sent to: ” + studentName);
  //sets priority
  msg.setPriority(Message.Priority.HIGH);
  //send the message
  Transport.send(msg);

9.5 Lets catch any exceptions and notify the user if the message was sent.

  catch (Exception me) {
    System.err.println(me);
  }
                 
  Dialog.alert(studentName + " has been emailed!");