Package com.sun.mail.smtp

Examples of com.sun.mail.smtp.SMTPMessage


          props.remove("password");
        }
        SessionAndTransport sat = SMTPConnectionPool.getSessionAndTransport(props,hash(props),auth);
       
  // Contacts
    SMTPMessage msg = new SMTPMessage(sat.session);
    if(from==null)throw new MessagingException("you have do define the from for the mail");
    //if(tos==null)throw new MessagingException("you have do define the to for the mail");
   
    checkAddress(from,charset);
    //checkAddress(tos,charset);
   
    msg.setFrom(from);
    //msg.setRecipients(Message.RecipientType.TO, tos);
     
    if(tos!=null){
      checkAddress(tos,charset);
      msg.setRecipients(Message.RecipientType.TO, tos);
      }
    if(ccs!=null){
      checkAddress(ccs,charset);
        msg.setRecipients(Message.RecipientType.CC, ccs);
      }
      if(bccs!=null){
      checkAddress(bccs,charset);
        msg.setRecipients(Message.RecipientType.BCC, bccs);
      }
      if(rts!=null){
      checkAddress(rts,charset);
        msg.setReplyTo(rts);
      }
      if(fts!=null){
      checkAddress(fts,charset);
        msg.setEnvelopeFrom(fts[0].toString());
      }
     
  // Subject and headers
      try {
      msg.setSubject(MailUtil.encode(subject, charset));
    } catch (UnsupportedEncodingException e) {
      throw new MessagingException("the encoding "+charset+" is not supported");
    }
    msg.setHeader("X-Mailer", xmailer);
   
    msg.setHeader("Date",getNow(timeZone));
      //msg.setSentDate(new Date());
     
      Multipart mp=null;
     
    // Only HTML
    if(plainText==null) {
      if(ArrayUtil.isEmpty(attachmentz) && ArrayUtil.isEmpty(parts)){
        fillHTMLText(msg);
        setHeaders(msg,headers);
        return new MimeMessageAndSession(msg,sat);
      }
      mp = new MimeMultipart();
      mp.addBodyPart(getHTMLText());
    }
    // only Plain
    else if(htmlText==null) {
      if(ArrayUtil.isEmpty(attachmentz) && ArrayUtil.isEmpty(parts)){
        fillPlainText(msg);
        setHeaders(msg,headers);
        return new MimeMessageAndSession(msg,sat);
      }
      mp = new MimeMultipart();
      mp.addBodyPart(getPlainText());
    }
    // Plain and HTML
    else {
      mp=new MimeMultipart("alternative");
      mp.addBodyPart(getPlainText());
      mp.addBodyPart(getHTMLText());
     
      if(!ArrayUtil.isEmpty(attachmentz) || !ArrayUtil.isEmpty(parts)){
        MimeBodyPart content = new MimeBodyPart();
        content.setContent(mp);
        mp = new MimeMultipart();
        mp.addBodyPart(content);
      }
    }
   
    // parts
    if(!ArrayUtil.isEmpty(parts)){
      Iterator<MailPart> it = parts.iterator();
      if(mp instanceof MimeMultipart)
        ((MimeMultipart)mp).setSubType("alternative");
      while(it.hasNext()){
        mp.addBodyPart(toMimeBodyPart(it.next()))
      }
    }
   
    // Attachments
    if(!ArrayUtil.isEmpty(attachmentz)){
      for(int i=0;i<attachmentz.length;i++) {
        mp.addBodyPart(toMimeBodyPart(mp,config,attachmentz[i]))
     
    }   
    msg.setContent(mp);
    setHeaders(msg,headers);
     
    return new MimeMessageAndSession(msg,sat);
  }
View Full Code Here


    Session session = Session.getInstance(props, g_auth);
    session.setDebug(true);

    try {
      g_smtpMsg = new SMTPMessage(session);
      g_smtpMsg.setFrom(new InternetAddress(g_from));

      InternetAddress[] address = getTos();
      if (address.length == 1)
        g_smtpMsg.setRecipient(Message.RecipientType.TO, address[0]);
View Full Code Here

                }
                return;
            }

            if (_smtpSession != null) {
                SMTPMessage msg = new SMTPMessage(_smtpSession);
                msg.setSender(new InternetAddress(_emailSender, _emailSender));
                msg.setFrom(new InternetAddress(_emailSender, _emailSender));
                for (InternetAddress address : _recipientList) {
                    msg.addRecipient(RecipientType.TO, address);
                }
                msg.setSubject(subject);
                msg.setSentDate(new Date());
                msg.setContent(content, "text/plain");
                msg.saveChanges();

                SMTPTransport smtpTrans = null;
                if (_smtpUseAuth) {
                    smtpTrans = new SMTPSSLTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                } else {
                    smtpTrans = new SMTPTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                }
                smtpTrans.connect();
                smtpTrans.sendMessage(msg, msg.getAllRecipients());
                smtpTrans.close();
            }
        }
View Full Code Here

                }
                return;
            }

            if (_smtpSession != null) {
                SMTPMessage msg = new SMTPMessage(_smtpSession);
                msg.setSender(new InternetAddress(_emailSender, _emailSender));
                msg.setFrom(new InternetAddress(_emailSender, _emailSender));
                for (InternetAddress address : _recipientList) {
                    msg.addRecipient(RecipientType.TO, address);
                }
                msg.setSubject(subject);
                msg.setSentDate(new Date());
                msg.setContent(content, "text/plain");
                msg.saveChanges();

                SMTPTransport smtpTrans = null;
                if (_smtpUseAuth) {
                    smtpTrans = new SMTPSSLTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                } else {
                    smtpTrans = new SMTPTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                }
                smtpTrans.connect();
                smtpTrans.sendMessage(msg, msg.getAllRecipients());
                smtpTrans.close();
            }
        }
View Full Code Here

            // File("D:\\Projects\\Synetek\\EverySpam\\DebugTests_Special");
            //File mailDir = new
            // File("D:\\Projects\\Synetek\\EverySpam\\DebugTests_Source");
            File mailDir = new File ("D:\\Projects\\Synetek\\Service\\EveryMail\\core\\poll");

            SMTPMessage mail = null;

            File[] files = mailDir.listFiles ();

            File output = new File ("c:/output.txt");

            if (output.exists ())
            {
                output.delete ();
            }

            FileOutputStream fout = new FileOutputStream (output);
            FileInputStream fin = null;

            StandardMimeMessageParser parser = null;

            JasenMessage jm = null;

            PrintWriter writer = new PrintWriter (fout);

            for (int i = 0; i < files.length; i++)
            {

                if (files[i].isFile ())
                {
                    try
                    {
                        writer.println ("*************************************************");
                        writer.println ("File " + (i + 1) + ": " + files[i].getName ());
                        writer.println ("*************************************************");

                        fin = new FileInputStream(files[i]);

                        mail = new SMTPMessage (null, fin);

                        parser = new StandardMimeMessageParser();
                        jm = parser.parse(mail);

                        writer.println ("HTML: " + jm.getHtmlPart());
View Full Code Here

                    }
                }

                String content = "You've been invited to join the CloudStack project id=" + projectId + ". Please use token " + token + " to complete registration";

                SMTPMessage msg = new SMTPMessage(_smtpSession);
                msg.setSender(new InternetAddress(_emailSender, _emailSender));
                msg.setFrom(new InternetAddress(_emailSender, _emailSender));
                msg.addRecipient(RecipientType.TO, address);
                msg.setSubject("You are invited to join the cloud stack project id=" + projectId);
                msg.setSentDate(new Date(DateUtil.currentGMTTime().getTime() >> 10));
                msg.setContent(content, "text/plain");
                msg.saveChanges();

                SMTPTransport smtpTrans = null;
                if (_smtpUseAuth) {
                    smtpTrans = new SMTPSSLTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                } else {
                    smtpTrans = new SMTPTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                }
                smtpTrans.connect();
                smtpTrans.sendMessage(msg, msg.getAllRecipients());
                smtpTrans.close();
            } else {
                throw new CloudRuntimeException("Unable to send email invitation; smtp ses");
            }
        }
View Full Code Here

                }
                return;
            }

            if (_smtpSession != null) {
                SMTPMessage msg = new SMTPMessage(_smtpSession);
                msg.setSender(new InternetAddress(_emailSender, _emailSender));
                msg.setFrom(new InternetAddress(_emailSender, _emailSender));
                for (InternetAddress address : _recipientList) {
                    msg.addRecipient(RecipientType.TO, address);
                }
                msg.setSubject(subject);
                msg.setSentDate(new Date());
                msg.setContent(content, "text/plain");
                msg.saveChanges();

                SMTPTransport smtpTrans = null;
                if (_smtpUseAuth) {
                    smtpTrans = new SMTPSSLTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                } else {
View Full Code Here

                    }
                }

                String content = "You've been invited to join the CloudStack project id=" + projectId + ". Please use token " + token + " to complete registration";

                SMTPMessage msg = new SMTPMessage(_smtpSession);
                msg.setSender(new InternetAddress(_emailSender, _emailSender));
                msg.setFrom(new InternetAddress(_emailSender, _emailSender));
                msg.addRecipient(RecipientType.TO, address);
                msg.setSubject("You are invited to join the cloud stack project id=" + projectId);
                msg.setSentDate(new Date(DateUtil.currentGMTTime().getTime() >> 10));
                msg.setContent(content, "text/plain");
                msg.saveChanges();

                SMTPTransport smtpTrans = null;
                if (_smtpUseAuth) {
                    smtpTrans = new SMTPSSLTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                } else {
                    smtpTrans = new SMTPTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                }
                smtpTrans.connect();
                smtpTrans.sendMessage(msg, msg.getAllRecipients());
                smtpTrans.close();
            } else {
                throw new CloudRuntimeException("Unable to send email invitation; smtp ses");
            }
        }
View Full Code Here

                }
                return;
            }

            if (_smtpSession != null) {
                SMTPMessage msg = new SMTPMessage(_smtpSession);
                msg.setSender(new InternetAddress(_emailSender, _emailSender));
                msg.setFrom(new InternetAddress(_emailSender, _emailSender));
                for (InternetAddress address : _recipientList) {
                    msg.addRecipient(RecipientType.TO, address);
                }
                msg.setSubject(subject);
                msg.setSentDate(new Date());
                msg.setContent(content, "text/plain");
                msg.saveChanges();

                SMTPTransport smtpTrans = null;
                if (_smtpUseAuth) {
                    smtpTrans = new SMTPSSLTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                } else {
                    smtpTrans = new SMTPTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                }
                smtpTrans.connect();
                smtpTrans.sendMessage(msg, msg.getAllRecipients());
                smtpTrans.close();
            }
        }
View Full Code Here

                }
                return;
            }

            if (_smtpSession != null) {
                SMTPMessage msg = new SMTPMessage(_smtpSession);
                msg.setSender(new InternetAddress(_emailSender, _emailSender));
                msg.setFrom(new InternetAddress(_emailSender, _emailSender));
                for (InternetAddress address : _recipientList) {
                    msg.addRecipient(RecipientType.TO, address);
                }
                msg.setSubject(subject);
                msg.setSentDate(new Date());
                msg.setContent(content, "text/plain");
                msg.saveChanges();

                SMTPTransport smtpTrans = null;
                if (_smtpUseAuth) {
                    smtpTrans = new SMTPSSLTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                } else {
                    smtpTrans = new SMTPTransport(_smtpSession, new URLName("smtp", _smtpHost, _smtpPort, null, _smtpUsername, _smtpPassword));
                }
                smtpTrans.connect();
                smtpTrans.sendMessage(msg, msg.getAllRecipients());
                smtpTrans.close();
            }
        }
View Full Code Here

TOP

Related Classes of com.sun.mail.smtp.SMTPMessage

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.