java mail problem

Discussion in 'Java' started by puropagol, Jul 3, 2003.

  1. puropagol

    puropagol Guest

    I wrote the following simple java mail program. While using the
    program on Windows it is working fine with our ISP, but when I am
    trying to run this on a solaris box .. I am getting a
    javax.mail.MessagingException saying could not connect to mail host.
    Both the machines are on the internet. Can anybody suggest what the
    problem is ?

    ******************************************************************************
    import java.util.*;
    import javax.mail.*;
    import javax.mail.internet.*;

    import com.sun.mail.smtp.SMTPTransport;

    public class SendMail {

    public static void sendMail(
    String mailHost,
    int mailPort,
    String userName,
    String password,
    String from,
    String to,
    String subject,
    String body) {

    try {
    Properties prop = System.getProperties();
    prop.put("mail.smtp.host", mailHost);
    Session session1 = Session.getInstance(prop, null);
    MimeMessage msg = new MimeMessage(session1);
    msg.setFrom(new InternetAddress(from));
    msg.addRecipient(Message.RecipientType.TO, new
    InternetAddress(to));
    msg.setSubject(subject);
    msg.setContent(body, "text/plain");
    SMTPTransport trans = new SMTPTransport(session1,new
    URLName(mailHost));
    trans.connect(mailHost,mailPort,userName,password);
    System.out.println(trans.isConnected());
    trans.sendMessage(msg, msg.getAllRecipients());
    trans.close();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    }
    ******************************************************************************
    puropagol, Jul 3, 2003
    #1
    1. Advertising

  2. I would start verifying the connection to SMTP server from the Solaris
    box using telnet.

    lekkim

    puropagol wrote:
    > I wrote the following simple java mail program. While using the
    > program on Windows it is working fine with our ISP, but when I am
    > trying to run this on a solaris box .. I am getting a
    > javax.mail.MessagingException saying could not connect to mail host.
    > Both the machines are on the internet. Can anybody suggest what the
    > problem is ?
    >
    > ******************************************************************************
    > import java.util.*;
    > import javax.mail.*;
    > import javax.mail.internet.*;
    >
    > import com.sun.mail.smtp.SMTPTransport;
    >
    > public class SendMail {
    >
    > public static void sendMail(
    > String mailHost,
    > int mailPort,
    > String userName,
    > String password,
    > String from,
    > String to,
    > String subject,
    > String body) {
    >
    > try {
    > Properties prop = System.getProperties();
    > prop.put("mail.smtp.host", mailHost);
    > Session session1 = Session.getInstance(prop, null);
    > MimeMessage msg = new MimeMessage(session1);
    > msg.setFrom(new InternetAddress(from));
    > msg.addRecipient(Message.RecipientType.TO, new
    > InternetAddress(to));
    > msg.setSubject(subject);
    > msg.setContent(body, "text/plain");
    > SMTPTransport trans = new SMTPTransport(session1,new
    > URLName(mailHost));
    > trans.connect(mailHost,mailPort,userName,password);
    > System.out.println(trans.isConnected());
    > trans.sendMessage(msg, msg.getAllRecipients());
    > trans.close();
    > } catch (Exception e) {
    > e.printStackTrace();
    > }
    > }
    > }
    > ******************************************************************************
    Mikkel Heisterberg, Jul 3, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TXJGZXo=?=

    Mail message size problem (System.Web.Mail)

    =?Utf-8?B?TXJGZXo=?=, Mar 14, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    637
    =?Utf-8?B?TXJGZXo=?=
    Mar 14, 2005
  2. =?Utf-8?B?TWlja2VCb3k=?=

    Problem with System.Web.Mail.MailMessage and HTML mail

    =?Utf-8?B?TWlja2VCb3k=?=, Jun 15, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    906
    =?Utf-8?B?TWlja2VCb3k=?=
    Jun 21, 2005
  3. =?Utf-8?B?T3Bh?=

    Sending Mail via System.Net.Mail problem

    =?Utf-8?B?T3Bh?=, Jan 25, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    3,599
    sachya
    Jan 31, 2006
  4. Brad
    Replies:
    2
    Views:
    9,993
  5. Replies:
    0
    Views:
    1,356
Loading...

Share This Page