显示邮件发件人不起作用javamail

时间:2019-02-05 08:34:43

标签: java outlook office365 javamail

我尝试从Java发送邮件,并且我希望在用户阅读邮件时显示发件人的电子邮件地址。

这是我的代码:

    public void sendMail(String smtp, String sender, String pswd, String receiver, String subject, String mailContent) {
    final String username = sender;
    final String passwd = pswd;
    final String from = sender;
    Properties props;
    props = new Properties();
    props.put("mail.smtp.host", "smtp.office365.com");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.port", "587");
    props.put("mail.smtp.starttls.enable", "true");

    Session session = Session.getInstance(props, new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
            return new PasswordAuthentication(sender, pswd);
        }
    });
    session.setDebug(true);

    try {
        MimeMessage msg = new MimeMessage(session);
        msg.setFrom(new InternetAddress("test_text <no-reply@society.be>"));
        msg.setRecipients(Message.RecipientType.TO,receiver);
        msg.setSubject(subject);
        msg.setSentDate(new Date());
        msg.setContent(mailContent, "text/html; charset=utf-8");
        msg.saveChanges();
        Transport.send(msg);

    } catch (MessagingException e) {
        System.out.println("Echec lors de l'envoi du mail : " + e);
        return;
    }
    System.out.println("Transmission du mail éffectuée avec succès !") ;
}

问题是Outlook(Office365)不能显示我想要的内容:

The sender name that is really display

我想要的是显示整个电子邮件地址或自定义名称,而不仅仅是“不答复”。

你们知道为什么这不起作用吗?

1 个答案:

答案 0 :(得分:0)

好的,因为 no-reply 是我们 AD 的用户,更改他的显示名称就可以了。我不知道我们 AD 中的显示名称会去掉自定义发件人名称。

相关问题