Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Java Mail problem

4 views
Skip to first unread message

Wendy S

unread,
Oct 25, 2002, 1:05:50 AM10/25/02
to

I can connect to the smtp server on port 25 and get it to work, and I can
send email "normally" using Ximian Evolution, so I'm fairly sure it isn't a
communication problem.

But when I try the simplest of the simple JavaMail test programs, I get
this:

[wendy@localhost mail]$ java -classpath /usr/j2sdkee1.3.1/lib/j2ee.jar:.
TestMail
Exception in thread "main" java.lang.NullPointerException
at java.net.InetAddress.cacheAddress(InetAddress.java:648)
at java.net.InetAddress.cacheAddress(InetAddress.java:633)
at
java.net.InetAddress.getAddressFromNameService(InetAddress.java:1016)
at java.net.InetAddress.getLocalHost(InetAddress.java:1125)
at
com.sun.mail.smtp.SMTPTransport.getLocalHost(SMTPTransport.java:84)
at
com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:159)
at javax.mail.Service.connect(Service.java:234)
at javax.mail.Service.connect(Service.java:135)
at javax.mail.Service.connect(Service.java:87)
at com.sun.mail.smtp.SMTPTransport.connect(SMTPTransport.java:93)
at javax.mail.Transport.send0(Transport.java:163)
at javax.mail.Transport.send(Transport.java:81)
at TestMail.postMail(TestMail.java:44)
at TestMail.main(TestMail.java:13)
[wendy@localhost mail]$

Here's the code:
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;

public class TestMail {

public static void main(String[] args) throws Exception {
String[] recip = {"som...@somewhere.com"};
String subject = "Testing JavaMail";
String message = "a test";
String from = "m...@myisp.com";
TestMail tm = new TestMail();
tm.postMail(recip, subject, message, from); //line 13
}


public void postMail(String recipients[], String subject, String me
ssage, String from) throws MessagingException {
boolean debug = false;

//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.myisp.com");

// create some properties and get the default Session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(debug);

// create a message
Message msg = new MimeMessage(session);

// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients[i]);
}
msg.setRecipients(Message.RecipientType.TO, addressTo);
// Optional : You can also set your custom headers in the
Email if you Want
msg.addHeader("MyHeaderName", "myHeaderValue");
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg); //line 44
}
}

I found this problem over and over with Google Groups, but I didn't see a
solution.

--
Wendy in Chandler, AZ

0 new messages