Package javax.mail

Examples of javax.mail.Message


      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


            }              
            Session session = Session.getInstance( props, null );
            session.setDebug( debug );
           
            // construct the message
            Message msg = new MimeMessage( session );
           
            msg.setFrom( new InternetAddress( from ) );
            msg.setReplyTo( new InternetAddress[] {  new InternetAddress( replyTo ) }  );
           
            for ( Recipient recipient : message.getRecipients().getRecipients() ) {
                RecipientType type = null;
                if ( "To".equals( recipient.getType() ) ) {
                    type = Message.RecipientType.TO;
                } else if ( "Cc".equals( recipient.getType() ) ) {
                    type = Message.RecipientType.CC;
                } else if ( "Bcc".equals( recipient.getType() ) ) {
                    type = Message.RecipientType.BCC;
                } else {
                    throw new RuntimeException( "Unable to determine recipient type" );
                }

                msg.addRecipients( type, InternetAddress.parse( recipient.getEmail(), false ) );
            }
            msg.setSubject( subject );
            collect( message.getBody(), msg );
            msg.setHeader( "X-Mailer", mailer );
            msg.setSentDate( new Date() );
           
            // send the thing off
          Transport t = (Transport)session.getTransport("smtp");
          try {
            t.connect(mailhost, username, password);
          t.sendMessage(msg, msg.getAllRecipients());
          } catch (Exception e) {
            throw new RuntimeException( "Connection failure", e );
           } finally {
            t.close();
          }
View Full Code Here

    int newMessageID = 0;

    try
    {
      // extract the RFC-822 message from the HashMap
      Message mesage[] = (Message[])mailMessage.get("message");

      // get the acocunt info from the HashMap and store it in another HashMap accountInfo
      HashMap accountInfo = (HashMap)mailMessage.get("account");

      String lastuidUpdate = (String)mailMessage.get("lastuidUpdate");
View Full Code Here

     
      byte b[] = (byte[])messageMap.get("inputstream");
      InputStream fis = new ByteArrayInputStream( b );
     
      MimeMessage messagefile = new MimeMessage( session , fis );
      Message mm [] = new Message[1];
      mm[0] = messagefile;
      messageMap.put( "message" , mm );
     
      InitialContext ic      = CVUtility.getInitialContext();
      MailDeliverLocalHome home  = (MailDeliverLocalHome)ic.lookup("local/MailDeliver");
View Full Code Here

        throws NamingException,
                   MessagingException
    {
        InitialContext ic = new InitialContext(  );
        Session        session = ( Session ) ic.lookup( _jndiSession );
        Message        msg = new MimeMessage( session );

        if ( from != null )
        {
            msg.setFrom( from );
        }
        else
        {
            msg.setFrom();
        }
        msg.setRecipients( javax.mail.Message.RecipientType.TO, to );
        msg.setSubject( subject );

        msg.setDataHandler( new DataHandler( body, mimeType ) );

        //msg.setHeader( "X-Mailer", "JavaMailer" );
        msg.setSentDate( new Date(  ) );

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

    int iLowerBound = iTotalCount-iMaxMsgs;
    if (iLowerBound<0) iLowerBound = 0;
    for (int m=iTotalCount-1; m>=iLowerBound && oList.size()<iMaxMsgs; m--) {
      if (DebugFile.trace) DebugFile.writeln("getting message "+String.valueOf(m));
      try {
        Message oMsgObj = oFldr.getMessage(m);

          if (!oMsgObj.isSet(Flags.Flag.DELETED) && !oMsgObj.isSet(Flags.Flag.ANSWERED)) {
            String sSpamFlag = ((MimeMessage) oMsgObj).getHeader("X-Spam-Flag","");
            if (sSpamFlag==null) sSpamFlag = "";
            if (!sSpamFlag.equalsIgnoreCase("YES")) {
              oHlpr.setMessage((MimeMessage) oMsgObj);
              String sMsgXML = oHlpr.toXML();
View Full Code Here

      }
   }

   public void sendEmail(String from, String to, String subject, String body)
         throws AddressException, MessagingException {
      Message message = getMessage();
      try {
         message.setFrom(new InternetAddress(from));
         InternetAddress tos[] = new InternetAddress[1];
         tos[0] = new InternetAddress(to);
         message.setRecipients(Message.RecipientType.TO, tos);
         message.setSubject(subject);
         message.setContent(body, "text/plain");
      } catch (MessagingException e) {
         throw e;
      }
      send(message);
   }
View Full Code Here

      String To = "receiver@there.com";
      String Subject = "Test";
      String body = "Test Body";

      Session session = Session.getInstance(this.getMailProperties(SMTP_PORT), null);
      Message msg = new MimeMessage(session);
      msg.setFrom(new InternetAddress(From));
      msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(To, false));
      msg.setSubject(Subject);

      msg.setText(body);
      msg.setHeader("X-Mailer", "musala");
      msg.setSentDate(new Date());

      Transport transport = null;

      try
      {
View Full Code Here

      {
         Session session = (Session) new InitialContext().lookup("java:/Mail");
         // create a message
         //
         Address replyToList[] = { replyTo };
         Message newMessage = new MimeMessage(session);
         newMessage.setFrom(from);
         newMessage.setReplyTo(replyToList);
         newMessage.setRecipients(Message.RecipientType.TO, to);
         newMessage.setSubject(subject);
         newMessage.setSentDate(new java.util.Date());
         newMessage.setText(message);

         // Send newMessage
          //
          Transport transport = session.getTransport();
          transport.connect();
View Full Code Here

        session = Session.getDefaultInstance(props, null);
      }


      // -- Create a new message --
      Message msg = new MimeMessage(session);

      // -- Set the FROM and TO fields --
      msg.setFrom(new InternetAddress(from));
      msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(
          to, false));

      // -- We could include CC recipients too --
      // if (cc != null)
      // msg.setRecipients(Message.RecipientType.CC
      // ,InternetAddress.parse(cc, false));

      // -- Set the subject and body text --
      msg.setSubject(subject);
      msg.setDataHandler(new DataHandler(new ByteArrayDataSource(body,
          "text/html; charset=\"utf-8\"")));

      // -- Set some other header information --
      msg.setHeader("X-Mailer", "XML-Mail");
      msg.setSentDate(new Date());

      // -- Send the message --
      Transport.send(msg);

      return "success";
View Full Code Here

TOP

Related Classes of javax.mail.Message

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.