If the problem is in your java, this is one simple way to configure your
mail Session, although there may be better alternatives these days:

    public Session getMailSession() {
        if (mailSession == null) {
            // Try and initialize if we have an IP address
            Properties props = System.getProperties();
            props.put("mail.host", getMailServerIPAddress());
            props.put("mail.smtp.host", getMailServerIPAddress());
            //props.put("mail.user", "admin");   // use this if
mailserver requires login/password
            props.put("mail.transport.protocol", "SMTP");
            
            mailSession = javax.mail.Session.getInstance(props);
            if (logger.isDebugEnabled()) {
                //mailSession.setDebug(true);
            }
        }
        return mailSession;
    } 


...and usage...


    public void send (SimpleMailMessage mail) throws MessagingException
{

        // GUARD CONDITION
        if (mail == null) return;
        
        // Create a javax.mail MimeMessage
        Message msg = new MimeMessage(getMailSession());
        if (mail.getFrom() != null) {
            msg.setFrom(new InternetAddress(mail.getFrom()));
        }

          // ...set all mail fields....

        try {
            // Ensure content
            if (msg.getFrom() != null &&
                msg.getAllRecipients() != null &&
msg.getAllRecipients().length > 0 &&
                msg.getSubject() != null &&
                msg.getContent() != null) {

                // SEND 
                Transport.send(msg);
            }
            else {
                if (logger.isDebugEnabled()) {
                    logger.debug("Not sending; empty content of message:
"+mail);
                }
            }
        }
        catch (IOException e) {
            logger.error("Error accessing content of message:
\n"+msg+"\nError: "+e);
        }
    }

The only real trick is setting up your javax.mail.Session - as I think I
recall, the Properties keys are not well documented. And this example
assumes you are communicating via SMTP with your James instance, so you
need the SMTP port to be snag-free.



-----Original Message-----
From: Jerry M [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, May 21, 2008 2:39 PM
To: James Users List
Subject: Re: sending email with a tomcat servlet, javamail + james

  First thing you need to do is see if and how far the mail is getting
into James.  Go to environment.xml and temporarily change all log levels
to "DEBUG".  Restart James, and try to send again.  Then if you have a
'grep' utility you can grep the James log directory for some unique
string in the sender address or recipient address of the email.  You can
fairly easily see what happens with the email through the James
pipeline.  If it doesn't show up at all in the James logs, then it
likely is not even getting into James, and you can focus you analysis on
the Tomcat side.

emailguy wrote:
> I'm running tomcat and James on the same machine. Both work 
> independently of each other. I'm trying to write a servlet that will 
> send an email to [EMAIL PROTECTED] via James. The servlet code 
> appears to run however, I'm not seeing the email received by 
> [EMAIL PROTECTED] The log files for Tomcat and James contain no 
> errors or are empty. Any suggestions are welcome. Are there any code 
> examples of this available? This must be a common thing to do.
>
> Thank you
>   


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


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

Reply via email to