@Test public void test() throws Exception { String subject = "测试邮件"; String content = "有任何疑问可以发邮件到 cdi-hadoop@Ctrip.com"; EMail.sendMail(subject, content, "xgliao@ctrip.com", null); }
public static int sendMail(String subject, String content, String mails, String cc) throws MessagingException { Properties props = new Properties(); props.put("mail.smtp.host", HOST); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.auth", "true"); Session mailSession = Session.getInstance(props, new MyAuthenticator()); Message message = new MimeMessage(mailSession); message.setFrom(new InternetAddress(FROM)); message.addRecipients(Message.RecipientType.TO, getMailList(mails)); message.addRecipients(Message.RecipientType.CC, getMailList(cc)); message.setSubject(subject); message.setContent(content, "text/html;charset=utf-8"); Transport transport = mailSession.getTransport("smtp"); try { transport.connect(HOST, USER, PASSWORD); transport.sendMessage(message, message.getAllRecipients()); } finally { if (transport != null) transport.close(); } return 0; }
EMail { public static int sendMail(String subject, String content, String mails, String cc) throws MessagingException { Properties props = new Properties(); props.put("mail.smtp.host", HOST); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.auth", "true"); Session mailSession = Session.getInstance(props, new MyAuthenticator()); Message message = new MimeMessage(mailSession); message.setFrom(new InternetAddress(FROM)); message.addRecipients(Message.RecipientType.TO, getMailList(mails)); message.addRecipients(Message.RecipientType.CC, getMailList(cc)); message.setSubject(subject); message.setContent(content, "text/html;charset=utf-8"); Transport transport = mailSession.getTransport("smtp"); try { transport.connect(HOST, USER, PASSWORD); transport.sendMessage(message, message.getAllRecipients()); } finally { if (transport != null) transport.close(); } return 0; } }
EMail { public static int sendMail(String subject, String content, String mails, String cc) throws MessagingException { Properties props = new Properties(); props.put("mail.smtp.host", HOST); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.auth", "true"); Session mailSession = Session.getInstance(props, new MyAuthenticator()); Message message = new MimeMessage(mailSession); message.setFrom(new InternetAddress(FROM)); message.addRecipients(Message.RecipientType.TO, getMailList(mails)); message.addRecipients(Message.RecipientType.CC, getMailList(cc)); message.setSubject(subject); message.setContent(content, "text/html;charset=utf-8"); Transport transport = mailSession.getTransport("smtp"); try { transport.connect(HOST, USER, PASSWORD); transport.sendMessage(message, message.getAllRecipients()); } finally { if (transport != null) transport.close(); } return 0; }  }
EMail { public static int sendMail(String subject, String content, String mails, String cc) throws MessagingException { Properties props = new Properties(); props.put("mail.smtp.host", HOST); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.auth", "true"); Session mailSession = Session.getInstance(props, new MyAuthenticator()); Message message = new MimeMessage(mailSession); message.setFrom(new InternetAddress(FROM)); message.addRecipients(Message.RecipientType.TO, getMailList(mails)); message.addRecipients(Message.RecipientType.CC, getMailList(cc)); message.setSubject(subject); message.setContent(content, "text/html;charset=utf-8"); Transport transport = mailSession.getTransport("smtp"); try { transport.connect(HOST, USER, PASSWORD); transport.sendMessage(message, message.getAllRecipients()); } finally { if (transport != null) transport.close(); } return 0; }  static int sendMail(String subject, String content, String mails,
			String cc); static InternetAddress[] getMailList(String mails); }
EMail { public static int sendMail(String subject, String content, String mails, String cc) throws MessagingException { Properties props = new Properties(); props.put("mail.smtp.host", HOST); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.auth", "true"); Session mailSession = Session.getInstance(props, new MyAuthenticator()); Message message = new MimeMessage(mailSession); message.setFrom(new InternetAddress(FROM)); message.addRecipients(Message.RecipientType.TO, getMailList(mails)); message.addRecipients(Message.RecipientType.CC, getMailList(cc)); message.setSubject(subject); message.setContent(content, "text/html;charset=utf-8"); Transport transport = mailSession.getTransport("smtp"); try { transport.connect(HOST, USER, PASSWORD); transport.sendMessage(message, message.getAllRecipients()); } finally { if (transport != null) transport.close(); } return 0; }  static int sendMail(String subject, String content, String mails,
			String cc); static InternetAddress[] getMailList(String mails); final static String HOST; final static String USER; final static String PASSWORD; final static String FROM; }