apche commons email

hellzlab

Junior member
  • Dec 22, 2007
    462
    13
    18
    Hell Lab
    I am using apache commons email to send mails from java. I want to send undelivered mail notification to another address not to the sender. So I used
    email.setBounceAddress("mail");
    ​
    but it is not working. Still the notification goes to the sender's address...How to get this done?
    Here is my CODE..

    try{
    Email email = new SimpleEmail();
    email.setHostName("smtp.googlemail.com");
    email.setSmtpPort(465);
    email.setAuthentication("MAIL", "PASSWORD");
    email.setSSLOnConnect(true);
    email.setFrom("MAIL");
    email.setSubject("Demo");
    email.setMsg("receieved");
    email.addTo("MAIL");
    email.setBounceAddress("[email protected]");
    email.send();
    System.out.println("email sent");
    }


    MACHLA KAWURU HARI DANNWNM UDAWWK DEEPLAKO???:):):)
     

    Shadow.Walker

    Well-known member
  • Jan 15, 2013
    3,757
    717
    113
    ██████████████
    When SMTP servers cannot deliver mail, they do not pay any attention to the contents of the message to determine where the error notification should be sent. Rather, they refer to the SMTP "envelope sender" value. JavaMail sets this value according to the value of the mail.smtp.from property on the JavaMail Session. (Commons Email initializes the JavaMail Session using System.getProperties()) If this property has not been set, then JavaMail uses the "from" address. If your email bean has the bounceAddress property set, then Commons Email uses it to set the value of mail.smtp.from when the Session is initialized, overriding any other value which might have been set.

    Note: This is the only way to control the handling of bounced email. Specifically, the "Errors-to:" SMTP header is deprecated and cannot be trusted to control how a bounced message will be handled. Also note that it is considered bad practice to send email with an untrusted "from" address unless you also set the bounce address. If your application allows users to enter an address which is used as the "from" address on an email, you should be sure to set the bounce address to a known good address.