Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > How to Send to Multiple People with Java.Mail

Reply
Thread Tools

How to Send to Multiple People with Java.Mail

 
 
Shane Jaworski
Guest
Posts: n/a
 
      06-29-2004
Here is a example

<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="javax.mail.*" %>
<%@ page import="javax.mail.internet.*" %>


<%

String toemail = "";
String fromemail = "";
String last_email = "";

Properties props = new Properties();
props.put("mail.smtp.host", mailserver);
last_email = "(E-Mail Removed)";
to_email = "(E-Mail Removed)";
fromemail = "(E-Mail Removed)";
toemail = toemail + "," + last_email;
Session mailSession = Session.getInstance(props, null);
Address fromUser = new InternetAddress(fromemail);
Address anotherUser = new InternetAddress(last_email);
Address[] toUser = InternetAddress.parse(toemail);
//Address toUser = new InternetAddress(toemail);
Message body = new MimeMessage(mailSession);
body.setRecipients(Message.RecipientType.TO, toUser);
body.setRecipient(Message.RecipientType.CC, fromUser);
body.setFrom(fromUser);
body.setSubject("Lots of Stuff.");
body.setContent("Sent: " + new java.util.Date() + "\n\nPlease respond
to this request as soon as possible.\n\n", "text/plain");
Transport.send(body);

%>
 
Reply With Quote
 
 
 
 
Sumukh
Guest
Posts: n/a
 
      06-29-2004
HI Shane,
You can read comma seperated list of recipients from some property
file/text file. Store the list in an arraylist.


String recipients=(String)props.getProperty("recipients") ;
ArrayList recipientsArray=new ArrayList();
StringTokenizer st = new StringTokenizer(recipients,",");
while (st.hasMoreTokens()) {
recipientsArray.add(st.nextToken());
}


and then you can set those reipients like this.

InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
int sizeTo=recipientsArray.size();
InternetAddress[] addressTo = new InternetAddress[sizeTo];
for (int i = 0; i < sizeTo; i++)
{
addressTo[i] = new InternetAddress(recipientsArray.get(i).toString()) ;
}
msg.setRecipients(Message.RecipientType.TO, addressTo);




hth

Sumukh





Shane Jaworski wrote:

> Here is a example
>
> <%@ page import="java.sql.*" %>
> <%@ page import="java.util.*" %>
> <%@ page import="javax.mail.*" %>
> <%@ page import="javax.mail.internet.*" %>
>
>
> <%
>
> String toemail = "";
> String fromemail = "";
> String last_email = "";
>
> Properties props = new Properties();
> props.put("mail.smtp.host", mailserver);
> last_email = "(E-Mail Removed)";
> to_email = "(E-Mail Removed)";
> fromemail = "(E-Mail Removed)";
> toemail = toemail + "," + last_email;
> Session mailSession = Session.getInstance(props, null);
> Address fromUser = new InternetAddress(fromemail);
> Address anotherUser = new InternetAddress(last_email);
> Address[] toUser = InternetAddress.parse(toemail);
> //Address toUser = new InternetAddress(toemail);
> Message body = new MimeMessage(mailSession);
> body.setRecipients(Message.RecipientType.TO, toUser);
> body.setRecipient(Message.RecipientType.CC, fromUser);
> body.setFrom(fromUser);
> body.setSubject("Lots of Stuff.");
> body.setContent("Sent: " + new java.util.Date() + "\n\nPlease respond
> to this request as soon as possible.\n\n", "text/plain");
> Transport.send(body);
>
> %>

 
Reply With Quote
 
 
 
 
Sumukh
Guest
Posts: n/a
 
      06-29-2004
HI Shane,
You can read comma seperated list of recipients from some property
file/text file. Store the list in an arraylist.


String recipients=(String)props.getProperty("recipients") ;
ArrayList recipientsArray=new ArrayList();
StringTokenizer st = new StringTokenizer(recipients,",");
while (st.hasMoreTokens()) {
recipientsArray.add(st.nextToken());
}


and then you can set those reipients like this.

InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
int sizeTo=recipientsArray.size();
InternetAddress[] addressTo = new InternetAddress[sizeTo];
for (int i = 0; i < sizeTo; i++)
{
addressTo[i] = new InternetAddress(recipientsArray.get(i).toString()) ;
}
msg.setRecipients(Message.RecipientType.TO, addressTo);




hth

Sumukh





Shane Jaworski wrote:

> Here is a example
>
> <%@ page import="java.sql.*" %>
> <%@ page import="java.util.*" %>
> <%@ page import="javax.mail.*" %>
> <%@ page import="javax.mail.internet.*" %>
>
>
> <%
>
> String toemail = "";
> String fromemail = "";
> String last_email = "";
>
> Properties props = new Properties();
> props.put("mail.smtp.host", mailserver);
> last_email = "(E-Mail Removed)";
> to_email = "(E-Mail Removed)";
> fromemail = "(E-Mail Removed)";
> toemail = toemail + "," + last_email;
> Session mailSession = Session.getInstance(props, null);
> Address fromUser = new InternetAddress(fromemail);
> Address anotherUser = new InternetAddress(last_email);
> Address[] toUser = InternetAddress.parse(toemail);
> //Address toUser = new InternetAddress(toemail);
> Message body = new MimeMessage(mailSession);
> body.setRecipients(Message.RecipientType.TO, toUser);
> body.setRecipient(Message.RecipientType.CC, fromUser);
> body.setFrom(fromUser);
> body.setSubject("Lots of Stuff.");
> body.setContent("Sent: " + new java.util.Date() + "\n\nPlease respond
> to this request as soon as possible.\n\n", "text/plain");
> Transport.send(body);
>
> %>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
People Helping People!!!!!!!!!!!! celeste96795@aol.com Java 1 06-11-2008 05:49 PM
Some people tell that at present, most web hosting servers supportall kinds of programming language, some people tell me that many web hostingserver don't support Java, What is the truth? Erwin Moller Java 3 05-07-2008 05:09 PM
javamail only send to people within the same domain Lin Java 5 01-16-2007 10:20 AM
people helping people......king kong, underworld 2, mi3, movie, dvd,music, games cam slade Computer Support 1 01-19-2006 06:07 AM
How to send an e_mail to multiple people without them seeing all the other addresses Computer Support 2 05-28-2004 11:38 PM



Advertisments