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.
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);
}
Comment