2013-11-02 54 views
0

我目前使用這個腳本來發送客戶郵件。但收件箱中的「發件人」名稱顯示爲: [email protected]。我想把這個名字設置爲Full House。我怎麼做?從java郵件中的名字設置

public Mail(Speler speler) throws MessagingException { 

    final String username = "[email protected]"; 
    final String password = "password"; 

    Properties props = new Properties(); 
    props.put("mail.smtp.auth", "true"); 
    props.put("mail.smtp.starttls.enable", "true"); 
    props.put("mail.smtp.host", "smtp.gmail.com"); 
    props.put("mail.smtp.port", "587"); 

    Session session = Session.getInstance(props, 
      new javax.mail.Authenticator() { 

       protected PasswordAuthentication getPasswordAuthentication() { 
        return new PasswordAuthentication(username, password); 
       } 
      }); 

    Message message = new MimeMessage(session); 
    message.setFrom(new InternetAddress("Full House")); 
    message.setRecipients(Message.RecipientType.TO, 
      InternetAddress.parse(speler.email)); 
    message.setSubject("Bevestiging van betaling " + "- Toernooi: " + speler.ToernooiID); 
    message.setText("Geachte heer/mevrouw " + speler.naam + "," 
      + "\n\n Uw betaling voor toernooi: " + speler.ToernooiID + " is geaccepteerd." 
      + "\n\n Met vriendelijke groet," 
      + "\n Full House"); 

    Transport.send(message); 

    System.out.println("Done"); 

} 

}

+1

請在問問題之前先搜索。您的問題的解決方案在http://stackoverflow.com/questions/1567467/setting-the-from-name-in-a-javax-mail-mimemessage – dirkk

回答

0
message.setFrom(new InternetAddress("[email protected]","Full House")); 
+0

工作!謝謝! –

+0

這個答案太短,不符合SO質量標準。請通過增加一些解釋來提高其質量,以便它對整個社區有用,而不僅僅用於OP。 –