import javax.mail.*; import javax.mail.internet.*; public class myMimeMessage { public static void addFrom(MimeMessage msg, String from) throws javax.mail.MessagingException { InternetAddress[] addresses = { new InternetAddress(from) }; msg.addFrom(addresses); } public static void setFrom(MimeMessage msg, String from) throws javax.mail.MessagingException { InternetAddress address = new InternetAddress(from); msg.setFrom(address); } public static void setReplyTo(MimeMessage msg, String replyTo) throws javax.mail.MessagingException { InternetAddress[] addresses = { new InternetAddress(replyTo) }; msg.setReplyTo(addresses); } // add a single entry (String) public static void addTo(MimeMessage msg, String to) throws javax.mail.MessagingException { Message.RecipientType t = Message.RecipientType.TO; msg.addRecipient(t, new InternetAddress(to)); } public static void addCC(MimeMessage msg, String cc) throws javax.mail.MessagingException { Message.RecipientType t = Message.RecipientType.CC; msg.addRecipient(t, new InternetAddress(cc)); } public static void addBCC(MimeMessage msg, String bcc) throws javax.mail.MessagingException { Message.RecipientType t = Message.RecipientType.BCC; msg.addRecipient(t, new InternetAddress(bcc)); } }