Hello,
I'm trying to send a mail with a SMTP-Server, which needs SMTP-Auth.
The code attached to this posting works perfect if executed from a shell, but i need this function in a servlet running on a Tomcat 4.1 webcontainer.

The DEBUG in a shell says:
<<DEBUG SMTP: useEhlo true, useAuth true

The Tomcat debug however says:
<<DEBUG SMTP: useEhlo true, useAuth false

and the sending fails. It looks as if Tomcat does not support SMTP Auth. Is there a possibility to replace some Tomcat jars with jars from J2EE?

Any help is appreciated, thanks

Jan Ulrich


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

class sendMessageApp {
static String host = "mail.gmx.net";
static String user = "somebody";
static String password = "secret";
static boolean debug = true;
static String toAddress = "to@you";
static String fromAddress = "from@me";

public static void main(String[] argv) {
// set the host
Properties props = new Properties();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth","true");
//create some properties and get the default session
Session session = Session.getDefaultInstance(props, null);
session.setDebug(true);

try {
System.out.println("Getting Transport for smtp");
Transport tr = session.getTransport("smtp");
try {
tr.connect("mail.gmx.net",user, password);
}
catch (MessagingException ex) {
ex.printStackTrace();
System.exit(1);
}

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

// set the from
InternetAddress from = new InternetAddress(fromAddress);
msg.setFrom(from);
InternetAddress[] address = {new InternetAddress(toAddress)};
msg.setRecipients(Message.RecipientType.TO, address);
msg.setSubject("This is a test");

msg.setContent("hello","text/plain");
msg.saveChanges();
System.out.println("Before sending...");
tr.sendMessage(msg, address);
}
catch (javax.mail.MessagingException mex) {
mex.printStackTrace();
}
}
}


--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to