#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    14
    Rep Power
    0

    Javamail - could not connect to SMTP host error


    Hi folks,


    I've got a JSP site set up and want to include an email facility - however, I keep getting the error: "Could not connect to SMTP host" when I try to run the code below. If anyone has any ideas as to where I'm going wrong, I'd be most grateful.

    Thanks,


    Fiona


    public class EmailBean
    {

    private String whoTo = "miss_fmp@yahoo.co.uk";
    private String sub = "EmailBean in action!";
    private String text = "Check 1 2";

    public EmailBean() throws Exception
    {
    try
    {
    Properties props = new Properties();
    props.put("mail.smtp.host", "smtp.mail.yahoo.com");
    props.put("mail.smtp.auth", "true");

    Session s = Session.getInstance(props);

    SMTPMessage message = new SMTPMessage(s);

    InternetAddress from = new InternetAddress("miss_fmp@yahoo.co.uk");
    message.setFrom(from);
    InternetAddress to = new InternetAddress(whoTo);
    message.addRecipient(Message.RecipientType.TO, to);

    message.setSubject(sub);
    message.setText(text);

    // My book says I need this for Yahoo
    Store store = s.getStore("pop3");
    store.connect("pop.mail.yahoo.com", "miss_fmp", "mypassword");

    System.out.println("just before send");
    Transport transport = s.getTransport("smtp");

    // I get this next line, then nothing else
    System.out.println("Got here");

    transport.connect("smtp.mail.yahoo.com", "miss_fmp", "mypassword");
    System.out.println("Made it to here");
    message.saveChanges();
    transport.sendMessage(message, message.getAllRecipients());
    transport.close();


    System.out.println("after send");

    // Next line for Yahoo again
    store.close();

    System.out.println("Made it");
    }
    catch (Exception e)
    {
    System.out.println(e.toString());
    }
    }

    public static void main (String [] args) throws Exception
    {
    EmailBean eb = new EmailBean();
    System.out.println("Done");
    }

    }
  2. #2
  3. Modding: Oracle MsSQL Firebird
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2001
    Location
    Outside US
    Posts
    8,527
    Rep Power
    539
    are you shure that smtp.mail.yahoo.com is correct? can you ping it and connect to it through telnet?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    14
    Rep Power
    0
    I'm pretty sure it is correct - this page has it listed, and countless other google sources turn up the same information.

    http://www.buzzsoft.com/engsupport/SMTP%20Host.html


    fiona

IMN logo majestic logo threadwatch logo seochat tools logo