Connecting Tech Pros Worldwide Forums | Help | Site Map

java mail API

Member
 
Join Date: Aug 2007
Posts: 50
#1: Dec 23 '07
This time my task is to send a real message to the specified email address.

The signatures for my method is

void sendEmail (EmailAddress emailAddress, String message)

I have gone through a sun tutorial regarding java mail several times and I can understand what is happening. Though my problem is that I don't know how to implement it.

In the tutorial there is an example code of how to send a message though the method has a different signature from mine. When I try to use the same code several errors evolve.

This is the method that I tried to implement. I know the method is a disaster... There are a lot of errors... :( If some1 can help me how to fix this method it would be really appreciated. This is since the deadline for my task is very soon.. :(

thanks very much for your time.

Expand|Select|Wrap|Line Numbers
  1.     public void sendEmail (EmailAddress emailAddress, String message) {
  2.  
  3.   String host = ...;
  4. String from = ...;
  5. String to = ...;
  6.  
  7. // Get system properties
  8. Properties props = System.getProperties();
  9.  
  10. // Setup mail server
  11. props.put("mail.smtp.host", host);
  12.  
  13. // Get session
  14. Session session = Session.getDefaultInstance(props, null);
  15.  
  16. // Define message
  17. MimeMessage message = new MimeMessage(session);
  18. message.setFrom(new InternetAddress(from));
  19. message.addRecipient(Message.RecipientType.TO, 
  20.   new InternetAddress(to));
  21. message.setSubject("Hello JavaMail");
  22. message.setText("Welcome to JavaMail");
  23.  
  24. // Send message
  25. Transport.send(message);
  26.  
  27.  
  28.  
  29.  
  30.     }
  31.  

JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Dec 24 '07

re: java mail API


That code is the demonstration code that comes with the javamail package.
What's wrong with it then? I used that code for starters when I installed the
package. Did you read the accompanying readme file for the installation
instructions? e.g. where to put the .jar etc.

kind regards,

Jos
Reply