You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-user@james.apache.org by Hattan Shobokshi <ha...@purevis.com> on 2002/07/31 00:11:06 UTC

Cannot send e-mail from mailet using Java Mail API

Problem:
I have created an auto response mailet that simply sends an e-mail back 
indicating the server is active.
The mailet was successfully deployed and is able to receive e-mail 
messages. Sending outgoing e-mail via
the Java mail API is not working. A local copy of James on my Win98 
machine works fine though.
I think the problem is because the linux server has 2 ip addresses . 
This is because we host 2 web sites on the
same box. I edited the config.xml file to bind the smtp server to the 
correct IP address. I also changed
the host name. In the method that sends e-mail out though I use a 
different mail server however i still get an
exception stating that it couldn't connect to localhost. Because I am 
sending the message using a static method in the
Transport Object does James force the Transport to use localhost? The 
Code that sends the e-mail is basic
JAVA Mail API calls and I copied that code and tried to run it as a 
stand alone application and works fine.

Thank you and I appreciate any help on this.

Hattan

Server:
James 2.0a3

OS:
Red Hat Linux

Exception:
  nested exception is:
        javax.mail.MessagingException: Could not connect to SMTP host: 
localhost, port: 25;
  nested exception is:
        java.net.ConnectException: Connection refused
javax.mail.SendFailedException: Sending failed;
  nested exception is:
        javax.mail.MessagingException: Could not connect to SMTP host: 
localhost, port: 25;
  nested exception is:
        java.net.ConnectException: Connection refused
        at javax.mail.Transport.send0(Transport.java:219)



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Cannot send e-mail from mailet using Java Mail API

Posted by Danny Angus <da...@apache.org>.
> So we have two sets of recipients: one set in the MimeMessage, and another
> carried within the MailImpl object.  Without knowing the convention used
> within JAMES, which we should document, there is no way to know
> which set of
> recipients will be used without tracing the code all the way to
> Transport.send[Message]().

Recipients as an argument to sendMail() is used, or the recipients from
James' MailImpl.
recipients in MimeMessage will be used After the message leaves James (eg
downstream MTA's)

 One way of using the transport overrides the
> recipients in MimeMessage, the other doesn't.  As best I can tell from
> RemoteDelivery, the convention in JAMES is to put the real recipients in
> MailImpl's collection, allowing the MimeMessage to have "display names"
> (e.g., a list name).
>
> If this understanding is correct,

Sort of, the "recipients" are used in the SMTP RCPT TO: command, the
MimeMessage recipients are placed in the message header.
Therfore there are reasonable grounds for having two sets (Bcc'ed mail for
example)


>my earlier interpretation is wrong.
> Either way, we really should document the convention and clean up
> the code.
> Furthermore, if I am correct as to how we are using the recipient list(s),
> I'd like to suggest that the MimeMessage's recipient list be used as the
> real list unless MailImpl's collection is not null.  That would eliminate
> the potential for error and cut down on redundant data.  And it is a
> backwards compatible change.
>
> FWIW, the sample configuration in the Javadoc still refers to
> NotifyPostmaster.

Why should it not?

d.



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Cannot send e-mail from mailet using Java Mail API

Posted by "Noel J. Bergman" <no...@devtech.com>.
> > IIRC, the one caveat is that NotifiySender is currently hardcoded
> > to notify the Postmaster as well, because it assumes that the
> > message is a problem.

> Are you sure?

Not entirely, no, and the more I read, the more I think I was mistaken.

I had taken a quick look and found this:

        //Create the list of recipients in the Address[] format
        InternetAddress[] rcptAddr = new InternetAddress[1];
        rcptAddr[0] =
getMailetContext().getPostmaster().toInternetAddress();
        reply.setRecipients(Message.RecipientType.TO, rcptAddr);

which I initially took to mean that we were setting the recipient to be the
postmaster address.  I now believe this code to be incorrect but "harmless."
Later on we have (edited for brevity):

        //Create the list of recipients in our MailAddress format
        Set recipients = new HashSet();
        recipients.add(mail.getSender());
        ...
        //Send it off...
        getMailetContext().sendMail(notifier, recipients, reply);

So we have two sets of recipients: one set in the MimeMessage, and another
carried within the MailImpl object.  Without knowing the convention used
within JAMES, which we should document, there is no way to know which set of
recipients will be used without tracing the code all the way to
Transport.send[Message]().  One way of using the transport overrides the
recipients in MimeMessage, the other doesn't.  As best I can tell from
RemoteDelivery, the convention in JAMES is to put the real recipients in
MailImpl's collection, allowing the MimeMessage to have "display names"
(e.g., a list name).

If this understanding is correct, my earlier interpretation is wrong.
Either way, we really should document the convention and clean up the code.
Furthermore, if I am correct as to how we are using the recipient list(s),
I'd like to suggest that the MimeMessage's recipient list be used as the
real list unless MailImpl's collection is not null.  That would eliminate
the potential for error and cut down on redundant data.  And it is a
backwards compatible change.

FWIW, the sample configuration in the Javadoc still refers to
NotifyPostmaster.

	--- Noel


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Cannot send e-mail from mailet using Java Mail API

Posted by Danny Angus <da...@apache.org>.
> IIRC, the one caveat is that NotifiySender is currently hardcoded 
> to notify
> the Postmaster as well, because it assumes that the message is a problem.

Are you sure?

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Cannot send e-mail from mailet using Java Mail API

Posted by "Noel J. Bergman" <no...@devtech.com>.
> I have created an auto response mailet that simply sends an e-mail back

Why didn't you use the NotifySender mailet?

<mailet match="All" class="NotifySender">
  <attachStackTrace>false</attachStackTrace>
  <notice>The server has received your message, and is alive</notice>
</mailet>

IIRC, the one caveat is that NotifiySender is currently hardcoded to notify
the Postmaster as well, because it assumes that the message is a problem.

	--- Noel


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>