1

Thanks for the prompt information for the queries posted.

Herez the problem am facing. Am trying to send an email. I want to add my custom headers. From outlook when am seeing the headers are missing

    // Recipient's email ID needs to be mentioned.
    String to = "sarveswararao.n123@gmail.com";

    // Sender's email ID needs to be mentioned
    String from = "snallamilli@xxx.com";

    // Assuming you are sending email from localhost
     String host = "smtp.xxx.com";

      String bounceAddr = "email_framework@xxx.onmicrosoft.com";

    // Get system properties
    Properties properties = System.getProperties();

    // Setup mail server
    properties.setProperty("mail.smtp.host", host);

    //This property will go as RETURN-PATH
      properties.setProperty("mail.smtp.from", bounceAddr);

    // Get the default Session object.
    Session session = Session.getDefaultInstance(properties);

    try {
        // Create a default MimeMessage object.
        MimeMessage message = new MimeMessage(session);

        // Set From: header field of the header.
        message.setFrom(new InternetAddress(from));

        // Set To: header field of the header.
        message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));

        // Set Subject: header field
        message.setSubject("This is the Subject Line!");

        // Now set the actual message
        message.setText("This is actual message");

        message.setHeader("x-mycustom-info", "value");  




        // Send message
        Transport.send(message);
        System.out.println("Sent message successfully....");
    } catch (MessagingException mex) {
        mex.printStackTrace();
    }
Jan
  • 13,738
  • 3
  • 30
  • 55
nsarvesh
  • 37
  • 1
  • 2
  • 9
  • try message.saveChanges() before you send - or (additionally?) message.writeTo(System.out); and check if the header is really missing on SEND or if maybe some mail server stripped it before you receive it in Outlook – Jan Jun 08 '17 at 19:38
  • How are you viewing the headers in Outlook? – Bill Shannon Jun 08 '17 at 20:40
  • Jan and Bill, Thanks for responding. I deeply analyzed the issue. The problem is if the to address is wrongly typed then we are redirecting to "email_framework@xxx.onmicrosoft.com" So when the email are redirected the custom headers that are set are removed by the outlook mail server. I believe that either the to address mail server or outlook mail server is stripping out the headers. My Use case is to track all the bounced email address. So thought of adding custom header and put email id in the custom header. so that i can avoid parsing the email body for getting the wrongly typed email id. – nsarvesh Jun 09 '17 at 02:21
  • Am seeing the headers from outlook open the email and click on File > Properties >> Internet Headers – nsarvesh Jun 09 '17 at 02:27

0 Answers0