电子邮件中缺少标题

时间:2017-06-08 18:19:40

标签: header javamail response.addheader

感谢您发布的查询的提示信息。

这是我面临的问题。我正在尝试发送电子邮件。我想添加自定义标头。从看到标题丢失时的展望

    // 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();
    }

0 个答案:

没有答案