java mail API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sugard
    New Member
    • Aug 2007
    • 50

    #1

    java mail API

    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.

    Code:
        public void sendEmail (EmailAddress emailAddress, String message) {
            
      String host = ...;
    String from = ...;
    String to = ...;
    
    // Get system properties
    Properties props = System.getProperties();
    
    // Setup mail server
    props.put("mail.smtp.host", host);
    
    // Get session
    Session session = Session.getDefaultInstance(props, null);
    
    // Define message
    MimeMessage message = new MimeMessage(session);
    message.setFrom(new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO, 
      new InternetAddress(to));
    message.setSubject("Hello JavaMail");
    message.setText("Welcome to JavaMail");
    
    // Send message
    Transport.send(message);
     
    
     
            
        }
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    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

    Comment

    Working...