dcsimg
How do I send email to multiple email addresses.
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Monday, February 18, 2002 09:00 AM

Can JavaMail send a note/message with and attachment to multiple email addresses? Also, how do I do that? Thanks.

Re: How do I send email to multiple email addresses.

Posted By:   mahesh_kalluri  
Posted On:   Saturday, March 2, 2002 12:55 AM

/*
submit an html form which contains textboxes for "from,to,cc,bcc,subject,content" to this .jsp file.
Do change your mailhost name this file.your message will be sent automatically.
*/


<%@ page import = "java.io.IOException,java.io.PrintWriter,java.sql.*,java.util.Hashtable,java.util.Properties" %>
<%@ page import =" javax.mail.*,javax.mail.internet.InternetAddress,javax.mail.internet.MimeMessage" %>
<%@ page import = "javax.servlet.*,javax.servlet.http.*" %>

<%

try
{
String actmailhost = "xxxxxx";//your mailhost
String actfrom = request.getParameter("from");
String actto = request.getParameter("to");
actto=actto+"-";
actto=actto.trim();

String actcc = request.getParameter("cc");
actcc=actcc+"-";
actcc=actcc.trim();

String actbcc = request.getParameter("bcc");
actbcc=actbcc+"-";
actbcc=actbcc.trim();

String actsubject = request.getParameter("subject");
String actcontent = request.getParameter("content");

Properties properties = new Properties();
properties.put("mail.smtp.host", actmailhost);
properties.put("mail.from", actfrom);

Session session1 = Session.getInstance(properties, null);
MimeMessage mimemessage = new MimeMessage(session1);

InternetAddress[] to=null;
InternetAddress[] cc=null;
InternetAddress[] bcc=null;

mimemessage.setFrom(new InternetAddress(actfrom));
mimemessage.setSubject(actsubject);
mimemessage.setContent(actcontent.toString(), "text/html");

Transport transport = session1.getTransport("smtp");
transport.connect();

if (!actto.equals("-"))
{
actto = actto.substring(0,actto.length()-1);
to = InternetAddress.parse(actto);
mimemessage.setRecipients(Message.RecipientType.TO, to);
transport.sendMessage(mimemessage, to);
}

if (!actcc.equals("-"))
{
actcc = actcc.substring(0,actcc.length()-1);
cc = InternetAddress.parse(actcc);
mimemessage.setRecipients(Message.RecipientType.CC, cc);
transport.sendMessage(mimemessage, cc);
}

if (!actbcc.equals("-"))
{
actbcc = actbcc.substring(0,actbcc.length()-1);
bcc = InternetAddress.parse(actbcc);
mimemessage.setRecipients(Message.RecipientType.BCC, bcc);
transport.sendMessage(mimemessage, bcc);
}

out.println("




");
out.println("
");
out.println("");
out.println("

");
out.println("Your Message has been successfully posted to the specified users.");
out.println("

Back

");

}
catch(Exception _ex)
{
out.println("




");
out.println("
");
out.println("");
out.println("

");
out.println("Problem in submitting the form.");
out.println("

Back

");
}
%>

Re: How do I send email to multiple email addresses.

Posted By:   Sharona_Feinberg  
Posted On:   Tuesday, February 19, 2002 05:37 AM

write the email addresses with comma as a separation.



and use :



MimeMessage message;


String to;


message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to,false) );



good luck

Re: How do I send email to multiple email addresses.

Posted By:   John_Zukowski  
Posted On:   Monday, February 18, 2002 06:10 PM

Sending messages, including attachments, and providing multiple TO addresses are all covered in the FAQ.
About | Sitemap | Contact