send email to list of users with different timezones?

Posted by ylazez on Stack Overflow See other posts from Stack Overflow or by ylazez
Published on 2010-06-09T21:18:46Z Indexed on 2010/06/09 21:22 UTC
Read the original article Hit count: 233

Filed under:
|

i use the following method to send email to list of users

  • i want the (To) in each email to be for just the user only not all users i.e appears to the users that the email is sent to only him my guess is to loop on:

    message.addRecipients(Message.RecipientType.TO, address);

then send the message right? , but this is a heavy process sending an email many times any ideas ?

  • suppose that i have the timezone for each user and i want to send each user the message in his timzone, the same issue i guess setting sent date for each user in his timezone then sending the message, right ?

the method is:

try {
                Properties props = System.getProperties();
                props.put("mail.smtp.host", "localhost");

                // Get a mail session
                Session session = Session.getDefaultInstance(props, null);

                // Define a new mail message
                Message message = new MimeMessage(session);
                InternetAddress ia = new InternetAddress();
                ia.setPersonal("MySite");
                ia.setAddress(from);
                message.setFrom(ia);

                Address[] address = new Address[recievers.size()];
                for (int i = 0; i < recievers.size(); i++) {
                    address[i] = new InternetAddress(recievers.get(i));
                }
                message.addRecipients(Message.RecipientType.TO, address);
                message.setSubject(subject);

                // Create a message part to represent the body text
                BodyPart messageBodyPart = new MimeBodyPart();
                messageBodyPart.setContent(body, "text/html");

                // use a MimeMultipart as we need to handle the file attachments
                Multipart multipart = new MimeMultipart();

                // add the message body to the mime message
                multipart.addBodyPart(messageBodyPart);

                // Put all message parts in the message
                message.setContent(multipart);

                message.setSentDate(getCurrentDate());
                // Send the message
                Transport.send(message);

            } catch (Exception ex) {}

© Stack Overflow or respective owner

Related posts about java

Related posts about javamail