Java Mail

Hi all I just tried to do the Java Mail tutorial but can not get it working. Here is my code:

import java.util.*;

import java.io.*;

import javax.mail.*;

import javax.mail.event.*;

import javax.mail.internet.*;

import javax.activation.*;

publicclass BasicJavaMail{

publicstaticvoid main(String args[]){

//Strings

String text =new String("text");

String subject =new String("subject");

String fromAdd =new String("scotthendo@gmail.com");

String toAdd =new String("scotthendo@hotmail.com");

String ccAdd =new String();

String fromName =new String("Scott");

String mailhost =null;

try

{

Properties props =new Properties();

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

Session sess = Session.getDefaultInstance(props,null);

MimeMessage mess =new MimeMessage(sess);

mess.setText(text);

mess.setSubject(subject);

Address fromAddress =new InternetAddress(fromAdd, fromName);

mess.setFrom(fromAddress);

Address toAddress =new InternetAddress(toAdd);

Address ccAddress =new InternetAddress(ccAdd);

mess.addRecipient(Message.RecipientType.TO, toAddress);

mess.addRecipient(Message.RecipientType.CC, ccAddress);

mess.saveChanges();// implicit with send()

Transport transport = sess.getTransport("smtp");

transport.connect(host, username, password);

transport.sendMessage(mess, mess.getAllRecipients());

transport.close();

sess.setDebug(true);

}

catch (Exception e){}

}

}

It compiles and runs but I dont recieve the email, I have unblocked Java from my firewall so thats not the problem.

Thankyou in advance for any help

Scott.

[3154 byte] By [scotthendoaua] at [2007-10-3 3:56:12]
# 1
1.) Don't write 'new String("whatever")'! It's not a good thing to do, simply replace it with "whatever"2.) You've got an empty catch-block, don't do this! There is probably some exception beeing thrown but you don't see it. At least put "e.printStackTrace()" there!
JoachimSauera at 2007-7-14 21:54:22 > top of Java-index,Java Essentials,New To Java...
# 2
Do this not after but before the actions:sess.setDebug(true);
BIJ001a at 2007-7-14 21:54:22 > top of Java-index,Java Essentials,New To Java...
# 3
Thanks for help the problem was the mailhost bit and thanks for the pointers!
scotthendoaua at 2007-7-14 21:54:22 > top of Java-index,Java Essentials,New To Java...
# 4

the first thing i see is that

you need to connect to to an smtp server

String mailhost = null;

try

{

Properties props = new Properties();

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

you are passing in a null to the host

read more on how this stuff works

i found a great example here

http://www.javacommerce.com/displaypage.jsp?name=javamail.sql&id=18274

discussjava.com_a at 2007-7-14 21:54:22 > top of Java-index,Java Essentials,New To Java...