Package javax.mail

Examples of javax.mail.Session


        props.put("mail.smtp.port", smtpPort);
        props.put("mail.smtp.socketFactory.port", smtpPort);
        props.put("mail.smtp.socketFactory.class", SSL_FACTORY);
        props.put("mail.smtp.socketFactory.fallback", "false");
      
        Session session = Session.getDefaultInstance(props,
        new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication(user,password);
                }
            }
        );
      
        session.setDebug(debug);
      
        Message msg = new MimeMessage(session);
        InternetAddress addressFrom = new InternetAddress(from);
        msg.setFrom(addressFrom);
        msg.setReplyTo(new Address[]{addressFrom});
      
        InternetAddress[] addressTo = new InternetAddress[recipients.length];
        for (int i = 0; i < recipients.length; i++) {
            addressTo[i] = new InternetAddress(recipients[i]);
        }
        //msg.setRecipients(Message.RecipientType.BCC, addressTo);
  
        MimeMultipart multipart = new MimeMultipart("alternative");
       
        if(attachmentURL!=null) {
          MimeBodyPart filePart = new MimeBodyPart();
          filePart.setFileName( attachmentFileName );
         
      URL url = new URL(attachmentURL);
      URLConnection connection = url.openConnection();
      connection.setRequestProperty( "User-Agent","OpenForum");
         
          ByteArrayDataSource ds = new ByteArrayDataSource(connection.getInputStream(), attachmentMimeType);
          filePart.setDataHandler(new DataHandler(ds));
          multipart.addBodyPart(filePart);
        }
       
        MimeBodyPart textPart = new MimeBodyPart();
        textPart.setContent(textMessage, "text/plain");
        multipart.addBodyPart(textPart);
       
        if(htmlMessage!=null) {
          MimeBodyPart htmlPart = new MimeBodyPart();
          String htmlData = htmlMessage;
          htmlPart.setContent(htmlData, "text/html");
          multipart.addBodyPart(htmlPart);
        }
       
        // Setting the Subject and Content Type
        msg.setSubject(subject);
        msg.setContent(multipart);
       
        Transport transport = session.getTransport(addressTo[0]);
        transport.addTransportListener(this);
        transport.connect();
        // Sending Message
        for(Address to: addressTo) {
          try{
View Full Code Here


    public static Boolean SentEmail(String email, String name, String subject, String content)
    {
      Boolean result = Boolean.valueOf(true);
      Properties props = new Properties();
      Session session = Session.getDefaultInstance(props, null);

      System.out.println(email + name + subject + content + "sayavn2013@gmail.com");
      try {
        Message msg = new MimeMessage(session);
        msg.setFrom(
View Full Code Here

    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
        // Note: The Session class is final, so it can't be mocked.  That
        // makes it almost impossible to test this method in any useful way.
        try {
            Properties props = new Properties();
            Session session = Session.getDefaultInstance(props, null);
            MimeMessage message = new MimeMessage(session, request.getInputStream());
            Address[] recipients = message.getRecipients(RecipientType.TO);
            if (recipients != null && recipients.length > 0) {
                LOGGER.debug("Discarding email message sent to " + recipients[0]);
            }
View Full Code Here

public class EmailSvc {

  public String sendEmail() {
   
    Properties props = new Properties();
    Session session = Session.getDefaultInstance(props, null);
    Message message = null;
   
    try {
     
      message = new MimeMessage(session);
View Full Code Here

        if (StringUtils.isEmpty(subject)) {
            throw new CedarRuntimeException("Must provide subject.");
        }

        Session session = Session.getDefaultInstance(new Properties(), null);
        Message message = new MimeMessage(session);
        message.setFrom(sender);
        message.setSubject(subject);

        for (InternetAddress recipient : recipients) {
View Full Code Here

      Properties props = new Properties();
      props.put("mail." + this.protocol + ".auth", "true");
      props.put("mail.transport.protocol", this.protocol);
      props.put("mail." + this.protocol + ".host", this.smtpHost);
      props.put("mail." + this.protocol + ".port", String.valueOf(this.port));
      Session session = Session.getDefaultInstance(props, null);
      transport = session.getTransport(this.protocol);
      transport.connect(this.smtpHost, this.userName, this.passWord);
     
      for (int i = 0; i < mailMessage.length; ++i) {
        mailMessage[i].setSession(session);
        transport.sendMessage(mailMessage[i].getMessage(),mailMessage[i].getMessage().getAllRecipients());
View Full Code Here

     */
    public MailMessageSender(String smtpHost) {
        smtpHost = smtpHost.trim();

        Properties properties = new Properties();
        Session session = Session.getDefaultInstance(properties);

        if ("null".equals(smtpHost)) {
            properties.put("mail.smtp.host", "127.0.0.1");
        } else {
            properties.put("mail.smtp.host", smtpHost);
View Full Code Here

public class MimeMessageParserTest
{
    @Test
    public void testParseSimpleEmail() throws Exception
    {
        final Session session = Session.getDefaultInstance(new Properties());
        final MimeMessage message = MimeMessageUtils.createMimeMessage(session, new File("./src/test/resources/eml/simple.eml"));
        final MimeMessageParser mimeMessageParser = new MimeMessageParser(message);

        mimeMessageParser.parse();
View Full Code Here

    }

    @Test
    public void testParseSimpleReplyEmail() throws Exception
    {
        final Session session = Session.getDefaultInstance(new Properties());
        final MimeMessage message = MimeMessageUtils.createMimeMessage(session, new File("./src/test/resources/eml/simple-reply.eml"));
        final MimeMessageParser mimeMessageParser = new MimeMessageParser(message);

        mimeMessageParser.parse();
View Full Code Here

    @Test
    public void testParseHtmlEmailWithAttachments() throws Exception
    {
        DataSource dataSource;
        final Session session = Session.getDefaultInstance(new Properties());
        final MimeMessage message = MimeMessageUtils.createMimeMessage(session, new File("./src/test/resources/eml/html-attachment.eml"));
        final MimeMessageParser mimeMessageParser = new MimeMessageParser(message);

        mimeMessageParser.parse();
View Full Code Here

TOP

Related Classes of javax.mail.Session

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.