"identifier expected" problem

i'm newbie in java field

i encounter the problem in my problem when i do the compilation. here are my error:

sendMail.java:14: <identifier> expected

props.put("mail.smtp.host", host);

^

sendMail.java:21: <identifier> expected

message.setFrom(new InternetAddress(from));

^

sendMail.java:22: <identifier> expected

message.addRecipient(message.RecipientType.TO,

^

sendMail.java:24: <identifier> expected

message.setSubject("Hello JavaMail");

^

sendMail.java:25: <identifier> expected

message.setText("Welcome to JavaMail");

^

sendMail.java:28: <identifier> expected

Transport.send(message);

^

6 errors

and this is my program code:

package common;

import javax.mail.*;

import com.sun.mail.smtp;

public class sendMail{

String host ="smtp.yahoo.com";

String from ="albertsie@yahoo.com";

String to ="albertsie@hotmail.com";

// 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);

}

how to solve this problem?

[1661 byte] By [albert85a] at [2007-10-2 10:08:50]
# 1

Your commands are outside of any method in the class.

public class sendMail{

String host ="smtp.yahoo.com";

String from ="albertsie@yahoo.com";

String to ="albertsie@hotmail.com";

// Get system properties

Properties props = System.getProperties();

// Setup mail server

props.put("mail.smtp.host", host);

Java ain't no C.

Consult

static void main(String args[])

BIJ001a at 2007-7-13 1:27:27 > top of Java-index,Developer Tools,Java Compiler...
# 2
import com.sun.mail.smtp;Besdies, you should not directy use com.sun.* stuff. Some Java tutorials would do good.
BIJ001a at 2007-7-13 1:27:27 > top of Java-index,Developer Tools,Java Compiler...
# 3

i already solve out that error but another error come out again:

the error are

sendMail.java:26: unreported exception javax.mail.internet.AddressException; must be caught or declared to be thrown

message.setFrom(new InternetAddress(from));

^

sendMail.java:26: unreported exception javax.mail.MessagingException; must be caught or declared to be thrown

message.setFrom(new InternetAddress(from));

^

sendMail.java:27: unreported exception javax.mail.internet.AddressException; must be caught or declared to be thrown

message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));

^

sendMail.java:27: unreported exception javax.mail.MessagingException; must be caught or declared to be thrown

message.addRecipient(Message.RecipientType.TO,new InternetAddress(to));

^

sendMail.java:28: unreported exception javax.mail.MessagingException; must be caught or declared to be thrown

message.setSubject("Hello JavaMail");

^

sendMail.java:29: unreported exception javax.mail.MessagingException; must be caught or declared to be thrown

message.setText("Welcome to JavaMail");

^

sendMail.java:32: unreported exception javax.mail.MessagingException; must be caught or declared to be thrown

Transport.send(message);

^

7 errors

i already my program to:

package common;

import java.util.*;

import javax.mail.internet.*;

import javax.mail.*;

public class sendMail{

static void main(String args[]){

String host ="smtp.yahoo.com";

String from ="albertsie@yahoo.com";

String to ="albertsie@hotmail.com";

// 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);

}

}

can anyone know what the error of this tell me please and how to solve this problem. thank you

regards albert

albert85a at 2007-7-13 1:27:27 > top of Java-index,Developer Tools,Java Compiler...
# 4

Each of the lines noted needs to be in a try - catch block, thus:

try

{

message.setFrom(new InternetAddress(from));

}

catch (internet.AddressException e)

{

// do something about the error

}

See this section of the Java Tutorial, which gives a full explanation and exmples:

http://java.sun.com/docs/books/tutorial/essential/exceptions/index.html

ChuckBinga at 2007-7-13 1:27:27 > top of Java-index,Developer Tools,Java Compiler...