• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Mail - How to send to Multiple recipients

 
Sanz Joanne
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey was wondering if anybody could help me i'm trying to set up javamail so that i can send out mailing lists from my website, here's the code i have what do i need to change???
<%@ page import="java.util.*, javax.mail.*, javax.mail.internet.*" %>
<%
Properties props = new Properties();
props.put("mail.smtp.host", "hoth.compsoc.com");
Session s = Session.getInstance(props,null);
MimeMessage message = new MimeMessage(s);
InternetAddress from = new InternetAddress("sanz@eircom.net");
message.setFrom(from);
//String toAddress = request.getParameter("to");
//InternetAddress to = new InternetAddress(toAddress);
//message.addRecipient(Message.RecipientType.TO, to);
String strName = /* request.getParameter("to"); */
InternetAddress[] address = InternetAddress.parse(strName);
message.setRecipients(Message.RecipientType.TO, address);
String subject = request.getParameter("subject");
message.setSubject(subject);
String text = request.getParameter("text");
message.setText(text);
Transport.send(message);
%>
<html>
<p align="center">The Message has been sent.<br>Check your inbox.</p>
<p align="center"><a href="Mail.html">Click here to send another!</a></p>
</html>

Thanks a mill
Sanz
 
Juanjo Bazan
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the addRecipients() method of the MimeMessage class, where you can set any number of addresses.
Just create an array of InternetAddress and set it as recipient of your message:


HTH
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!