Setting the from name in a javax.mail.MimeMessage?

后端 未结 4 2057
生来不讨喜
生来不讨喜 2020-12-08 18:28

Currently, our application uses a javax.mail to send email, using javax.mail.MailMessage. We set the From headers of the email this way:

Message msg = new Mi         


        
4条回答
  •  一整个雨季
    2020-12-08 19:05

    ic = new InitialContext();
    
    final Session session = (Session) ic.lookupLink(snName);
    final Properties props = session.getProperties();
    
    props.put("mail.from", mailFrom); //blabla@mail.com
    props.put("mail.from.alias", mailName);//"joao Ninguem"
    
    // Create a message with the specified information.
    final MimeMessage msg = new MimeMessage(session);
    msg.setSubject(subject);
    msg.setSentDate(new Date());
    
    msg.setFrom(new InternetAddress(session.getProperty("mail.from"), session.getProperty("mail.from.alias"), "UTF8"));
    
    
    msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(mailTo, false));
    msg.setContent(body, "text/html");
    
    // Create a transport.
    Transport.send(msg);
    

提交回复
热议问题