Hai ,
Please check the below code which helps u to send batch mails ..
import javax.mail.Folder;
import javax.mail.Store;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import java.util.Properties;
import java.sql.Connection;
import javax.sql.DataSource;
import java.sql.ResultSet;
import java.sql.Statement;
import java.sql.SQLException;
import java.util.Date;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.lang.String;
import java.text.SimpleDateFormat;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.action.DynaActionForm;
import java.util.ArrayList;
public final class PricingInfoAction extends Action
{
private static final String SMTP_HOST_NAME = "";
public String emailMsgTxt = null;
private static final String emailSubjectTxt = "Ad Order
Details";
private static final String emailFromAddress = "";
public ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
{
// Add List of Email address to who email needs to be sent to
String[] emailList = new String[2];
emailList[0]= new String("[EMAIL PROTECTED]");
emailList[1]= new String("[EMAIL PROTECTED]");
emailMsgTxt="Ad Order Details";
try {
postMail( emailList, emailSubjectTxt,
emailMsgTxt, emailFromAddress);
}catch (Exception e)
{
return
(mapping.findForward("mailfailure"));
}
}catch (Exception e) {
return (mapping.findForward("submitadfail"));
}
return (mapping.findForward(target));
}
public void postMail( String recipients[ ], String subject,
String message , String from) throws
MessagingException
{
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
Session session = Session.getDefaultInstance(props,
null);
session.setDebug(debug);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(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.TO, addressTo);
// Setting the Subject and Content Type
msg.setSubject(subject);
msg.setContent(message, "text/plain");
Transport.send(msg);
}
}
----- Original Message -----
From: "Caroline Jen" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>
Sent: Wednesday, October 13, 2004 7:41 PM
Subject: Re: how to send batch emails
> I have been using the same utility class (JavaMail
> API) to send e-mails. The code works OKay.
>
> Now, instead of the
>
> String toAddress
>
> I have String[] toAddress =
> selectRecipientsForm.getSelectedEmailAddresses();
>
> will the same code works for sending batch e-mails?
>
>
>
> --- Duncan Mills <[EMAIL PROTECTED]> wrote:
>
> > Its pretty simple to plug in the JavaMail API -
> > here's a Utility class I
> > call from an Action I use when resetting a User
> > Password: It's quick and
> > dirty but provides an example. The SMTP mail host
> > is read from a
> > properties file in this case, but equally could be
> > passed in from the
> > Appliciation scope. Note the total lack of any kind
> > of useful error
> > handling in this example - I think I better re-write
> > it :-)
> >
> > [--Badly formmated code begin--]
> > package com.groundside.util;
> > import java.io.IOException;
> > import java.io.InputStream;
> > import java.util.Properties;
> > import javax.mail.Message;
> > import javax.mail.MessagingException;
> > import javax.mail.Session;
> > import javax.mail.Transport;
> > import javax.mail.internet.InternetAddress;
> > import javax.mail.internet.MimeMessage;
> >
> > public class Emailer
> > {
> > String toAddress;
> > String fromAddress;
> > String msgText;
> > String smtpServer;
> > String msgSubject;
> >
> > public Emailer()
> > {
> > }
> >
> > public Emailer(String from, String to, String
> > subject, String message)
> > {
> > setFromAddress(from);
> > setToAddress(to);
> > setMsgSubject(subject);
> > setMsgText(message);
> > }
> >
> > public void sendMail()
> > {
> > Session session = null;
> > MimeMessage msg = null;
> > Properties props = new Properties();
> >
> > if (this.getSmtpServer() == null)
> > {
> > ClassLoader propLoader =
> > this.getClass().getClassLoader();
> > //Properties file just lives in the src root
> > InputStream is =
> > propLoader.getResourceAsStream("mailer.properties");
> > try
> > {
> > props.load(is);
> >
> > setSmtpServer((String)props.get("mail.smtp.host"));
> > }
> > catch (IOException iox)
> > {
> > System.out.println("Mail Properties load
> > failed " + iox.toString());
> > }
> >
> > }
> > else
> > {
> >
> > props.put("mail.smtp.host",this.getSmtpServer());
> > }
> >
> > session = Session.getDefaultInstance(props);
> > try
> > {
> > msg = new MimeMessage(session);
> >
> > msg.setFrom(new
> > InternetAddress(this.getFromAddress()));
> > msg.addRecipient(Message.RecipientType.TO,new
> > InternetAddress(this.getToAddress()));
> > msg.setSubject(getMsgSubject());
> > msg.setText(getMsgText());
> >
> > Transport.send(msg);
> > }
> > catch (MessagingException mex)
> > {
> > mex.printStackTrace();
> > }
> >
> >
> > }
> >
> > // Getters and Setters
> > public String getToAddress()
> > {
> > return toAddress;
> > }
> >
> > public void setToAddress(String toAddress)
> > {
> > this.toAddress = toAddress;
> > }
> >
> > public String getFromAddress()
> > {
> > return fromAddress;
> > }
> >
> > public void setFromAddress(String fromAddress)
> > {
> > this.fromAddress = fromAddress;
> > }
> >
> > public String getMsgText()
> > {
> > return msgText;
> > }
> >
> > public void setMsgText(String msgText)
> > {
> > this.msgText = msgText;
> > }
> >
> > public String getSmtpServer()
> > {
> > return smtpServer;
> > }
> >
> > public void setSmtpServer(String smtpServer)
> > {
> > this.smtpServer = smtpServer;
> > }
> >
> > public String getMsgSubject()
> > {
> > return msgSubject;
> > }
> >
> > public void setMsgSubject(String msgSubject)
> > {
> > this.msgSubject = msgSubject;
> > }
> > }
> >
> > [--Badly formmated code end--]
> >
> >
> > Regards
> >
> > Duncan Mills
> >
> >
> >
> > Richard wrote:
> >
> > >hi guys
> > >
> > >
> > >I have a form submitted to an action class and i
> > need the information
> > >on the form to be emailed
> > >to some email address. how can i do this ? can it
> > be done inside the
> > >same action?
> > >
> > >please help
> > >thanks
> > >richard
> > >
> >
> >---------------------------------------------------------------------
> > >To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > >For additional commands, e-mail:
> > [EMAIL PROTECTED]
> > >
> > >
> > >
> >
> >
> ---------------------------------------------------------------------
> > To unsubscribe, e-mail:
> > [EMAIL PROTECTED]
> > For additional commands, e-mail:
> > [EMAIL PROTECTED]
> >
> >
>
>
> __________________________________________________
> Do You Yahoo!?
> Tired of spam? Yahoo! Mail has the best spam protection around
> http://mail.yahoo.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]