Assuming that you are creating a new James MailImpl object, wrapping the MimeMessage,
and then sending it through James, you need to:
MailAddress reversePath = new MailAddress("[EMAIL PROTECTED]");
MimeMessage message = ...;
// assuming that From and To headers are set in the MimeMessage ... otherwise
see other constructors in MailImpl
Mail mail = new MailImpl(message);
// note: the mail name is not the same as the message's Message-ID header
((MailImpl) mail).setName(.....);
((MailImpl) mail).setSender(reversePath);
mail.getMessage().setHeader(RFC2822Headers.RETURN_PATH, "<" +
reversePath.toString + ">");
mail.getMessage().saveChanges();
getMailetContext().sendMail(mail);
Obviously there may be several variations (see MailImpl constructors and methods).
The crucial point is the MailImpl.setSender(MailAddress) method, that is not setting
the MimeMessage From header nor the Return-Path header, but the better called
"reverse-path". The setHeader(RFC2822Headers.RETURN_PATH ...) instruction is somehow
redundant, as the receiver MTA will set the Return-Path to the reverse-path; it's
better though to set it, as the MTA may not be RFC2821 compliant.
RFC2821 section 4.4 says:
[...]
When the delivery SMTP server makes the "final delivery" of a
message, it inserts a return-path line at the beginning of the mail
data. This use of return-path is required; mail systems MUST support
it. The return-path line preserves the information in the <reverse-
path> from the MAIL command. Here, final delivery means the message
has left the SMTP environment. Normally, this would mean it had been
delivered to the destination user or an associated mail drop, but in
some cases it may be further processed and transmitted by another
mail system.
[...]
Hope that it helps,
Vincenzo
> -----Original Message-----
> From: Bosco So [mailto:[EMAIL PROTECTED]
> Sent: luned� 8 settembre 2003 21.23
> To: James Users List
> Subject: setting Return-Path in mailet
>
>
> I'm generating email messages from within a mailet. How do I create a
> Return-Path header that's different from the From header? When I create
> email messages outside James using the JavaMail API, the following code
> gives me a Return-Path header that's different from the From header.
> However, the same code in James results in email messages where the
> Return-Path is taken from the From header (and the values I set in
> msg.setEnvelopeFrom is ignored).
>
> Properties props = new Properties();
> Session msess = Session.getDefaultInstance(props, null);
> SMTPMessage msg = new SMTPMessage(msess);
>
> String bounceAddress = "[EMAIL PROTECTED]";
> msg.setEnvelopeFrom(bounceAddress);
> try {
> msg.setFrom(new
> InternetAddress("[EMAIL PROTECTED]",
> "From Handler"));
> msg.setReplyTo(new InternetAddress[] {
> new
> InternetAddress("[EMAIL PROTECTED]",
> "Reply Handler")});
> }
> catch (java.io.UnsupportedEncodingException cannotHappen) {}
>
> msg.setRecipient(Message.RecipientType.TO,
> "[EMAIL PROTECTED]");
> msg.setSubject("test subject");
> msg.setContent("test message", "text/plain");
>
>
> Am using James 2.2.0a9 on RedHat Linux 8 with Sun JDK1.4.2.
>
>
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
> BOSCO SO www.groundspring.org
>
> Senior Software Engineer, Groundspring.org. Growing nonprofits
> with Internet tools and training.
>
> DonateNow: Accept credit card donations through your website
> EmailNow: Send eNewsletters and communicate with supporters
> ebase: Manage your stakeholder relationships
>
> Groundspring.org, P.O. Box 29256, San Francisco, CA 94129-0256
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
>
>
>
> ---------------------------------------------------------------------
> 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]