src/main/java/org/apache/hadoop/hdfs/server/namenode/analytics/MailOutput.java
public static void write(
      String subject,
      String html,
      String mailHost,
      String[] emailTo,
      String[] emailCc,
      String emailFrom)
      throws Exception {

    InternetAddress[] to = new InternetAddress[emailTo.length];
    for (int i = 0; i < emailTo.length && i < to.length; i++) {
      to[i] = new InternetAddress(emailTo[i]);
    }

    InternetAddress[] cc = null;
    if (emailCc != null) {
      cc = new InternetAddress[emailCc.length];
      for (int i = 0; i < emailCc.length && i < cc.length; i++) {
        cc[i] = new InternetAddress(emailCc[i]);
      }
    }

    // Sender's email ID needs to be mentioned
    InternetAddress from = new InternetAddress(emailFrom);

    // Get system properties
    Properties properties = System.getProperties();

    // Setup mail server
    properties.setProperty(MAIL_SMTP_HOST, mailHost);

    // Get the Session object.
    Session session = Session.getInstance(properties);

    // Create a default MimeMessage object.
    MimeMessage message = new MimeMessage(session);

    // INodeSet From: header field of the header.
    message.setFrom(from);

    // INodeSet To: header field of the header.
    message.addRecipients(Message.RecipientType.TO, to);
    if (cc != null && cc.length != 0) {
      message.addRecipients(Message.RecipientType.CC, cc);
    }

    // INodeSet Subject: header field
    message.setSubject(subject);

    // Send the actual HTML message, as big as you like
    MimeBodyPart bodyHtml = new MimeBodyPart();
    bodyHtml.setContent(html, MAIL_CONTENT_TEXT_HTML);

    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(bodyHtml);

    message.setContent(multipart);

    // Send message
    Transport.send(message);
  }
/**
   * Write and send an email.
   *
   * @param subject email subject
   * @param html the exact html to send out via email
   * @param mailHost email host
   * @param emailTo email to address
   * @param emailCc email cc addresses
   * @param emailFrom email from address
   * @throws Exception if email fails to send
   */
Write and send an email.
Write and send an email .
public static void write(
      String subject,
      String html,
      String mailHost,
      String[] emailTo,
      String[] emailCc,
      String emailFrom)
      throws Exception {
    InternetAddress[] to = new InternetAddress[emailTo.length];
    for (int i = 0; i < emailTo.length && i < to.length; i++) {
      to[i] = new InternetAddress(emailTo[i]);
    }
    InternetAddress[] cc = null;
    if (emailCc != null) {
      cc = new InternetAddress[emailCc.length];
      for (int i = 0; i < emailCc.length && i < cc.length; i++) {
        cc[i] = new InternetAddress(emailCc[i]);
      }
    }
    InternetAddress from = new InternetAddress(emailFrom);
    Properties properties = System.getProperties();
    properties.setProperty(MAIL_SMTP_HOST, mailHost);
    Session session = Session.getInstance(properties);
    MimeMessage message = new MimeMessage(session);
    message.setFrom(from);
    message.addRecipients(Message.RecipientType.TO, to);
    if (cc != null && cc.length != 0) {
      message.addRecipients(Message.RecipientType.CC, cc);
    }
    message.setSubject(subject);
    MimeBodyPart bodyHtml = new MimeBodyPart();
    bodyHtml.setContent(html, MAIL_CONTENT_TEXT_HTML);
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(bodyHtml);
    message.setContent(multipart);
    Transport.send(message);
  }
public static void write ( String subject , String html , String mailHost , String [ ] emailTo , String [ ] emailCc , String emailFrom ) throws Exception { InternetAddress [ ] to = new InternetAddress [ emailTo . length ] ; for ( int i = 0 ; i < emailTo . length && i < to . length ; i ++ ) { to [ i ] = new InternetAddress ( emailTo [ i ] ) ; } InternetAddress [ ] cc = null ; if ( emailCc != null ) { cc = new InternetAddress [ emailCc . length ] ; for ( int i = 0 ; i < emailCc . length && i < cc . length ; i ++ ) { cc [ i ] = new InternetAddress ( emailCc [ i ] ) ; } } InternetAddress from = new InternetAddress ( emailFrom ) ; Properties properties = System . getProperties ( ) ; properties . setProperty ( MAIL_SMTP_HOST , mailHost ) ; Session session = Session . getInstance ( properties ) ; MimeMessage message = new MimeMessage ( session ) ; message . setFrom ( from ) ; message . addRecipients ( Message . RecipientType . TO , to ) ; if ( cc != null && cc . length != 0 ) { message . addRecipients ( Message . RecipientType . CC , cc ) ; } message . setSubject ( subject ) ; MimeBodyPart bodyHtml = new MimeBodyPart ( ) ; bodyHtml . setContent ( html , MAIL_CONTENT_TEXT_HTML ) ; Multipart multipart = new MimeMultipart ( ) ; multipart . addBodyPart ( bodyHtml ) ; message . setContent ( multipart ) ; Transport . send ( message ) ; }
Write and send an email.
Write and send an email .
// Sender's email ID needs to be mentioned // Get system properties // Setup mail server // Get the Session object. // Create a default MimeMessage object. // INodeSet From: header field of the header. // INodeSet To: header field of the header. // INodeSet Subject: header field // Send the actual HTML message, as big as you like // Send message