Re: javamail code in servlet works locally, but not when uploaded to host
rexdtripod@hotmail.com wrote:
Hmmm... Nobody wants to come to the party... Guess I'll keep my own
thread going in case anyone else out there ever has the problem...
Here are the vitals on my local sandbox environment:
Servlet Container Apache tomcat-5.0.24
Java 1.4.2._04-b05
JavaMail 1.4
JavaBeans(tm)Activation Framework 1.1
The following source creates an email message and attachment and sends
via javamail. All works well in my local sandbox environment. Mail
message with attachment arrive without a hitch.
I've been working with my host on why deploying this produces no error
messages, but no mail message either. They are perplexed. They have
linux servers running Resin. Does anyone out there see any
incompatibility here?
<!--<?xml version="1.0"?>-->
<%@ page import="java.util.*" %>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.io.*" %>
<%@ page import="org.jdom.*" %>
<%@ page import="org.jdom.output.*" %>
<%@ page import="java.text.*" %>
<%@ page import="java.util.Properties" %>
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>
<%@ page import="javax.activation.*" %>
<!--<response>-->
<%
//Set up some error logging
File file = new File("./error.txt");
FileWriter f = new FileWriter(file);
// Wrap the filewriter with a bufferedwriter (creates an output
stream)
BufferedWriter b = new BufferedWriter (f);
//Wrap the buffered writer in a printwriter
PrintWriter pw = new PrintWriter (b,false);
Have you verified that this operation works on your deployment server? Where
is ./error.txt created, does the servlet have permission to create it? If this
fails you won't know whether there were any exceptions as your exception
reporting requires this step to work. This is wrapped around a BufferedWriter,
and I don't see any flush after writing to it, maybe the error is still in the
buffer? How do you view the contents of this file?
I would test this by generating some trace output to pw and verifying that I
could read it.
It is possible that your ISP is blocking access to their SMTP server from your
deployment server, but they ought to know their own acceptance rules...
Does your deployment server allow outgoing connections on port 25, it may be
firewalled?
--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@ion.le.ac.uk
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555