4

Problem that i'm solving is that when i send mail if the recipient (to mails, cc/bcc) not exist, i don't want sender to get Delivery Status Notification (Failure) mail.

The solution that i'm implementing is adding new header in mail Prevent-NonDelivery-Report

I want to add new header in MimeMessage msg in java

// this is part of the code that defined the mime message 
Session session = Session.getDefaultInstance(props, null);

// we create message
Message msg = new MimeMessage(session);

// this code is not working for me
msg.addHeader("Prevent-NonDelivery-Report", "");

I found the solution i add props.setProperty("mail.smtp.dsn.notify", "NEVER") to the property of the session and that fix my problem

Mr.Java
  • 369
  • 4
  • 16
  • 1
    Do you get any error, when you say "not working for me"? – Vikdor Nov 14 '12 at 09:24
  • There is no errors, this header is added to the message but Delivery Status Notification (Failure) mail is still send in my test inbox, my guess is that this header has to have value or my test mail server don't recognize this header – Mr.Java Nov 14 '12 at 10:11
  • Found the solution, i was on the wrong direction, i added props.setProperty("mail.smtp.dsn.notify", "NEVER"); to the property of the session, this is setting the Delivery Status Notification to Never so not i'm not getting Delivery Status Notification (Failure) mail – Mr.Java Nov 14 '12 at 14:29
  • 1
    You should add that comment as an answer and accept it yourself. It'll be easier to find. – João Mendes Nov 16 '12 at 16:01

1 Answers1

0

On behalf of the OP:

I found the solution. I add:

props.setProperty("mail.smtp.dsn.notify", "NEVER")

to the property of the session and that fix my problem.

Gerold Broser
  • 14,080
  • 5
  • 48
  • 107