james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Eric Charles <e...@apache.org>
Subject Re: bounce mail messages
Date Sat, 05 Jan 2013 18:08:51 GMT
With attachment tag begin 'none', you shouldn't have the original mail 
attached to the bounce mail.

Can you try with attachError set to false?

If it doesn't work out, you will have to debug. I do this ususally in 
eclipse and it's pretty powerful. The logic resides in AbstractRedirect 
(line 1189)

Thx, Eric

On 05/01/2013 17:43, Rajender Vallapureddy wrote:
> Hi Eric,
>
> Thank you for your help.
>
> I did as you suggested. I am getting the bounce mail, but also the
> original mail too.
>
> Following is my skeleton code of my mailet.
>
> public class CustomMailMailet extends AbstractNotify {
> 	@Override
> 	public void service(Mail mail) throws MessagingException {
>
>             if(condition fails) {
>                super.service(mail);
>             }
>         }
> }
>
> Following is the my configuration in the mailetcontainer.conf
>
>          <mailet match="com.webmail.matcher.CustomMailMatcher"
> class="com.webmail.mailet.CustomMailMailet">
>            <attachError>true</attachError>
>            <message>mail from non webmail client denied</message>
>            <prefix>bounce</prefix>
>            <attachment>none</attachment>
>            <passThrough>true</passThrough>
>            <debug>true</debug>
>          </mailet>
>
> Please guide me how can i get the bounce message only instead of the
> bounce message and the original message.
>
> Thank you in advance,
> Regards,
> Rajender
>
>
> On Sat, Jan 5, 2013 at 8:51 PM, Eric Charles <eric@apache.org> wrote:
>> Well, why don't you start from the existing Bounce mailet [1] (which extends
>> AbstractNotify) rather than wrapping the MailetContext?
>>
>> Thx, Eric
>>
>> [1]
>> https://svn.apache.org/repos/asf/james/server/trunk/mailets/src/main/java/org/apache/james/transport/mailets/Bounce.java
>>
>>
>> On 05/01/2013 15:44, Rajender Vallapureddy wrote:
>>>
>>> Hi Eric,
>>>
>>> I am writing a custom mailet and based on the condition, I might have
>>> to deny sending mail message and bounce it.
>>>
>>> My bounce method is getting called, but unable to bounce the mail message.
>>>
>>> I have written a helper class and implemented my bounce method.
>>>
>>> Following is the code.
>>>
>>> within my mailet I am calling the method bounce
>>>
>>> mailetcntxtwrapper = new MailetContextWrapper();
>>> mailetcntxtwrapper.bounce(mail, "Denied access from this message", new
>>> MailAddress(username));
>>>
>>>
>>> public class MailetContextWrapper implements MailetContext  {
>>>
>>>       @Override
>>>       public void bounce(Mail mail, String message, MailAddress bouncer)
>>> throws MessagingException {
>>>           if(mail == null) {
>>>                  System.out.println("Mail is null");
>>>           }
>>>
>>>          if (mail.getSender() == null) {
>>>               if (log.isInfoEnabled())
>>>                   log.info("Mail to be bounced contains a null (<>)
>>> reverse path.  No bounce will be sent.");
>>>               return;
>>>           } else {
>>>               // Bounce message goes to the reverse path, not to the
>>> Reply-To
>>>               // address
>>>               if (log.isInfoEnabled())
>>>                   log.info("Processing a bounce request for a message
>>> with a reverse path of " + mail.getSender().toString());
>>>           }
>>>
>>>           MailImpl reply = rawBounce(mail, message);
>>>           // Change the sender...
>>>           reply.getMessage().setFrom(bouncer.toInternetAddress());
>>>           reply.getMessage().saveChanges();
>>>           // Send it off ... with null reverse-path
>>>           reply.setSender(null);
>>>           sendMail(reply);
>>>           LifecycleUtil.dispose(reply);
>>>       }
>>>
>>>       /**
>>>        * Generates a bounce mail that is a bounce of the original message.
>>>        *
>>>        * @param bounceText the text to be prepended to the message to
>>> describe the bounce
>>>        *                   condition
>>>        * @return the bounce mail
>>>        * @throws MessagingException if the bounce mail could not be created
>>>        */
>>>       private MailImpl rawBounce(Mail mail, String bounceText) throws
>>> MessagingException {
>>>           System.out.println("rawbound method called");
>>>          // This sends a message to the james component that is a bounce of
>>> the
>>>           // sent message
>>>           MimeMessage original = mail.getMessage();
>>>           MimeMessage reply = (MimeMessage) original.reply(false);
>>>           reply.setSubject("Re: " + original.getSubject());
>>>           reply.setSentDate(new Date());
>>>           Collection<MailAddress> recipients = new HashSet<MailAddress>();
>>>           recipients.add(mail.getSender());
>>>           InternetAddress addr[] = {new
>>> InternetAddress(mail.getSender().toString())};
>>>           reply.setRecipients(Message.RecipientType.TO, addr);
>>>           reply.setFrom(new
>>> InternetAddress(mail.getRecipients().iterator().next().toString()));
>>>           reply.setText(bounceText);
>>>           reply.setHeader(RFC2822Headers.MESSAGE_ID, "replyTo-" +
>>> mail.getName());
>>>           return new MailImpl("replyTo-" + mail.getName(), new
>>> MailAddress(mail.getRecipients().iterator().next().toString()),
>>> recipients, reply);
>>> }
>>>
>>> }
>>>
>>> Please guide me to get my custom bounce working. Also I want to make
>>> sure that once the bounce happens, the mail is not processed any
>>> further. What configuration should I be looking at within the mailet
>>> configuration.
>>>
>>> Appreciate your help :)
>>>
>>> Thank you,
>>> Regards,
>>> Rajender
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>>> For additional commands, e-mail: server-dev-help@james.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
>> For additional commands, e-mail: server-dev-help@james.apache.org
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
> For additional commands, e-mail: server-dev-help@james.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message