Package javax.mail.internet

Examples of javax.mail.internet.MimeMessage$RecipientType


        int mailc = queue.read(mailSession, mails, null, 1);
        if(mailc > 1)
          timeToSleep = 0;
        if(mails.size()>0){
          for(;i<mails.size();i++){
            MimeMessage mail = (MimeMessage)mails.get(i);
            mail.setFrom(new InternetAddress(sender,"DLOG4J Messenger"));
            if(userDNSQuery){
              //�ؿ�ר��
              String email = mail.getRecipients(RecipientType.TO)[0].toString();
              String domain_name = parseDomain(email);
              //TODO: ʵ�������Ļ���,�ӿ�����ٶ�
              Lookup lookup = new Lookup(domain_name, Type.MX);
                  lookup.run();
              if (lookup.getResult() != Lookup.SUCCESSFUL){
View Full Code Here


   */
  public static void main(String[] args) throws MessagingException, TextParseException, UnsupportedEncodingException {
    for(int ai=0;ai<args.length;ai++){
      String mailaddr = args[ai];
      Session ssn = initMailSession();
      MimeMessage mailMessage = new MimeMessage(ssn);
      mailMessage.setSubject("Hello MAIL");
      mailMessage.setSentDate(new Date());
      //Properties props = ssn.getProperties();
          //props.put("mail.smtp.from", "<>");
 
          Multipart multipart = new MimeMultipart("related");
      MimeBodyPart messageBodyPart = new MimeBodyPart();
          messageBodyPart.setText("Welcome to JavaMail.");
          multipart.addBodyPart(messageBodyPart);
          mailMessage.setContent(multipart);
          mailMessage.setFrom(new InternetAddress("javayou@gmail.com","Winter Lau"));
         
          String mail_postfix = mailaddr.substring(mailaddr.indexOf('@')+1);
          //System.out.println("mail postfix is " + mail_postfix);
          Lookup lookup = new Lookup(mail_postfix, Type.MX);
          lookup.run();
View Full Code Here

    if(mails!=null){
      for(int i=0;i<mailfiles.length&&i<max_count;i++){
        FileInputStream fis = null;
        try{
          fis = new FileInputStream(mailfiles[i]);
          mails.add(new MimeMessage(ssn, fis));
          if(ident!=null)
            ident.add(mailfiles[i].getPath());
          fis.close();
          fis = null;
          mailfiles[i].delete();
View Full Code Here

    /**
     * Creates a new Mail object.
     */
    MailObject(Session session) {
        this.status = OK;
        message = new MimeMessage(session);
    }
View Full Code Here

        Session session = Session.getDefaultInstance(props);
        session.setDebug(true);
        session.setDebugOut(debugOut);

        MimeMessage message = createMimeMessage(session, mailMessage);
        log.debug("Sending message");
        Transport.send(message);
    }
View Full Code Here

        log.debug("Sending message");
        Transport.send(message);
    }

    private MimeMessage createMimeMessage(Session session, MailMessage mailMessage) throws MessagingException {
        MimeMessage message = new MimeMessage(session);
        InternetAddress[] to = createAddresses(mailMessage.getTo());
        InternetAddress[] cc = createAddresses(mailMessage.getCc());
        InternetAddress[] bcc = createAddresses(mailMessage.getBcc());
        MimeMultipart content = new MimeMultipart("related");

        //Create attachments
        DataSource[] attachments = mailMessage.getAttachments();
        for (int i = 0; i < attachments.length; i++) {
            DataSource attachment = attachments[i];
            MimeBodyPart attachmentPart = createAttachmentPart(attachment);
            content.addBodyPart(attachmentPart);
        }
       
        //Create message body
        MimeBodyPart bodyPart = createMessageBodyPart(mailMessage.getBody(), mailMessage.isBodyHtml());
        content.addBodyPart(bodyPart);

        if (from == null) {
            message.setFrom();
        } else {
            message.setFrom(new InternetAddress(from));
        }
        message.setRecipients(Message.RecipientType.TO, to);
        message.setRecipients(Message.RecipientType.CC, cc);
        message.setRecipients(Message.RecipientType.BCC, bcc);
        message.setSubject(mailMessage.getSubject());
        message.setContent(content);
        return message;
    }
View Full Code Here

        System.out.println( connection );
        Session session = Session.getInstance( connection,
                                               null );

        // Define message
        MimeMessage message = new MimeMessage( session );
        message.setHeader( "Content-Class",
                           "urn:content-classes:calendarmessage" );
        message.setHeader( "Content-ID",
                           "calendar_message" );

        String creatorEmail = userInfo.getEmailForEntity( creator );
        message.setFrom( new InternetAddress( creatorEmail ) );
        message.setReplyTo( new InternetAddress[]{new InternetAddress( creatorEmail )} );
        message.addRecipient( Message.RecipientType.TO,
                              new InternetAddress( userInfo.getEmailForEntity( owner ) ) );
        message.setSubject( "Task Assignment " + type + " Event: " + name );
        message.setSentDate( new Date() );

        // Create a Multipart
        Multipart multipart = new MimeMultipart( "alternative" );

        // Add text message
        BodyPart messageBodyPart = new MimeBodyPart();
        String text = "Summary\n-------\n\n" + summary + "\n\nDescription\n-----------\n\n" + description;
        messageBodyPart.setText( text );
        messageBodyPart.setDataHandler( new DataHandler( new ByteArrayDataSource( text,
                                                                                  "text/plain; charset=UTF8;" ) ) );
        multipart.addBodyPart( messageBodyPart );

        // Add ical
        messageBodyPart = new MimeBodyPart();
        String filename = "ical-" + type + "-" + taskId + ".ics";
        messageBodyPart.setFileName( filename );
        messageBodyPart.setHeader( "Content-Class",
                                   "urn:content-classes:calendarmessage" );
        messageBodyPart.setHeader( "Content-ID",
                                   "calendar_message" );
        String icalStr = getIcal( summary,
                                  description,
                                  startDate,
                                  priority,
                                  userInfo.getDisplayName( creator ),
                                  creatorEmail,
                                  type );

        messageBodyPart.setDataHandler( new DataHandler( new ByteArrayDataSource( icalStr,
                                                                                  "text/calendar; charset=UTF8; " ) ) );
        multipart.addBodyPart( messageBodyPart );

        message.setContent( multipart );
        message.saveChanges();

        Transport.send( message );
    }
View Full Code Here

      throw new RuntimeException("Opening Transport", e);
    }
    try {
        InternetAddress address = new InternetAddress(email);

        Message msg = new MimeMessage(session);

        msg.setFrom(new InternetAddress(configuration.getFromAddress()));

        msg.setRecipient(Message.RecipientType.TO, address);
        String title = "GVS Login Link";
        try {
          msg.setSubject(MimeUtility.encodeText(title, "UTF-8", null));
        } catch (UnsupportedEncodingException e) {
          throw new RuntimeException(e);

        }
        msg.setSentDate(new java.util.Date());
        // create and fill the first message part

        MimeBodyPart plainTextVersion = new MimeBodyPart();
        plainTextVersion.setDataHandler(new DataHandler(textDataSource));

        MimeBodyPart htmlPart = new MimeBodyPart();
        htmlPart.setDataHandler(new DataHandler(htmlDataSource));
        // create the Multipart
        // and its parts to it
        Multipart bodyAlternatives = new MimeMultipart("alternative");
        bodyAlternatives.addBodyPart(plainTextVersion);
        htmlPart.setHeader("Content-Type", "text/html; charset=UTF-8");
        bodyAlternatives.addBodyPart(htmlPart);



        // mbp1.setHeader("Content-Language", "fr");
        // add the Multipart to the message
        Multipart mainMultipart = new MimeMultipart();
        BodyPart body = new MimeBodyPart();
        body.setContent(bodyAlternatives);
        mainMultipart.addBodyPart(body);

        // mainMultipart.addBodyPart(getSerialializerRDFPart(mailModel));

        msg.setContent(mainMultipart);
        log.debug("mesage ready, sending");
        Transport.send(msg);
        /*
         * Reusing conncection: (problem:isp limits) Address[] recipients = new
         * Address[1]; recipients[0] = recipient; transport.sendMessage(msg,
View Full Code Here

        logger.error("[sendMessage]: The accountVO doesn't have a smtpserver setup: "+mailAccountVO);
        throw new SendFailedException("<error>The SMTP Server has not been setup.</error>");
      }

      Session session = Session.getDefaultInstance(props, null);
      MimeMessage message = new MimeMessage(session);

      Collection bccList = mailMessageVO.getBccList();
      Collection ccList = mailMessageVO.getCcList();
      Collection toList = mailMessageVO.getToList();
      Collection attachments = mailMessageVO.getAttachedFiles();
      String subject = mailMessageVO.getSubject();
      String body = mailMessageVO.getBody();
      String fromAddress = mailMessageVO.getFromAddress();
      String replyToAddress = mailMessageVO.getReplyTo();
      String headers = mailMessageVO.getHeaders();
      String messageType = mailMessageVO.getContentType();

      arrayBcc = this.getAddressAddress(bccList);
      arrayCc = this.getAddressAddress(ccList);
      arrayTo = this.getAddressAddress(toList);

      message.addRecipients(Message.RecipientType.TO, arrayTo);
      message.addRecipients(Message.RecipientType.CC, arrayCc);
      message.addRecipients(Message.RecipientType.BCC, arrayBcc);

      message.setFrom(new InternetAddress(fromAddress));
      // So we don't require a Reply-To address
      if (replyToAddress != null && replyToAddress.length() != 0) {
        message.setReplyTo(new Address[] {new InternetAddress(replyToAddress)});
      }
      //Add raw headers to message object
      StringTokenizer tokenizer = new StringTokenizer(headers, System.getProperty("line.separator", "\n"));
      while (tokenizer.hasMoreTokens()) {
        message.addHeaderLine(tokenizer.nextToken());
      }

      //Most email clients add this line with the name of
      //their software and the version
      message.addHeader("X-Mailer", "Centraview v. " + CentraViewConfiguration.getVersion());

      message.setSubject(subject);
      BodyPart messageBodyPart = new MimeBodyPart();
      messageBodyPart.setContent(body, messageType);

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

      // Handle attachments
      if (attachments != null) {
        message.setContent(multipart);
        Iterator attachmentIterator = attachments.iterator();
        while (attachmentIterator.hasNext()) {
          messageBodyPart = new MimeBodyPart();
          CvFileVO thisAttachment = (CvFileVO) attachmentIterator.next();
          String path = thisAttachment.getPhysicalFolderVO().getFullPath(null, true) + thisAttachment.getName();
          DataSource source = new FileDataSource(path);
          messageBodyPart.setDataHandler(new DataHandler(source));
          messageBodyPart.setFileName(thisAttachment.getTitle());
          multipart.addBodyPart(messageBodyPart);
        }
      }

      message.setSentDate(new Date());
      //End of Build The JavaMail message

      messageSent = this.sendSimpleMessage(message, mailAccountVO.getSmtpServer(),
        mailAccountVO.getLogin(), mailAccountVO.getPassword(), mailAccountVO.getSmtpPort(),
        mailAccountVO.isPopRequiredBeforeSMTP(), mailAccountVO.isAuthenticationRequiredForSMTP(),
View Full Code Here

      }else{
        throw new SendFailedException("<error>The SMTP Server has not been setup.</error>");
      }

      Session session = Session.getDefaultInstance(props, null);
      MimeMessage message = new MimeMessage(session);

      Collection bccList = mailMessageVO.getBccList();
      Collection ccList = mailMessageVO.getCcList();
      Collection toList = mailMessageVO.getToList();
      Collection attachments = mailMessageVO.getAttachedFiles();

      String subject = mailMessageVO.getSubject();
      String body = mailMessageVO.getBody();
      String fromAddress = mailMessageVO.getFromAddress();
      String replyToAddress = mailMessageVO.getReplyTo();
      String headers = mailMessageVO.getHeaders();
      String messageType = mailMessageVO.getContentType();

      //if you don't specify the from email address we will enter the administrator email address
      if(fromAddress == null){
        fromAddress =  adminEmailAddress;
      }
      message.setFrom(new InternetAddress(fromAddress));

      if (replyToAddress != null && !replyToAddress.equals("")){
        message.setReplyTo(new Address[] {new InternetAddress(replyToAddress)});
      }

      //Add raw headers to message object
      StringTokenizer tokenizer = new StringTokenizer(headers, System.getProperty("line.separator", "\n"));
      while (tokenizer.hasMoreTokens()) {
        message.addHeaderLine(tokenizer.nextToken());
      }

      //Most email clients add this line with the name of
      //their software and the version
      message.addHeader("X-Mailer", "Centraview v. " + CentraViewConfiguration.getVersion());

      message.setSubject(subject);
      BodyPart messageBodyPart = new MimeBodyPart();
      messageBodyPart.setContent(body, messageType);

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

      // Handle attachments
      if (attachments != null) {
        message.setContent(multipart);
        Iterator attachmentIterator = attachments.iterator();
        while (attachmentIterator.hasNext()) {
          messageBodyPart = new MimeBodyPart();
          CvFileVO thisAttachment = (CvFileVO) attachmentIterator.next();
          String path = thisAttachment.getPhysicalFolderVO().getFullPath(null, true) + thisAttachment.getName();
          DataSource source = new FileDataSource(path);
          messageBodyPart.setDataHandler(new DataHandler(source));
          messageBodyPart.setFileName(thisAttachment.getTitle());
          multipart.addBodyPart(messageBodyPart);
        }
      }

      message.setSentDate(new Date());

      String mailSendList = "";
      String mailFailedList = "";

      //End of Build The JavaMail message

      // We must have to send seperate message to individual.
      // We must have to keep track of message sent to list and failed while send message to particular individual.
      if (toList != null) {
        Iterator toIterator = toList.iterator();
        int count = 0;
        while (toIterator.hasNext()) {
          String toAddress = (String) toIterator.next();
          message.setRecipients(Message.RecipientType.TO, toAddress);
          try{
            messageSent = this.sendSimpleMessage(message, smtpServer, username, password, smtpPort, connectToPopFirst, smtpAuthenticationRequired, serverType, serverAddress);
          } catch(SendFailedException sfe) {
            // we will catch the invalid Address and by this way we will know that recipient will not receive the mail and we add individual in the failing list.
            Address[] invalidAddress = sfe.getInvalidAddresses();
View Full Code Here

TOP

Related Classes of javax.mail.internet.MimeMessage$RecipientType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.