Jagadeesh M
asked on
unable to frame multi-part for mailing..
Hi Guys,
Please help to frame....
I've SID, CID, MSG[1-n], String recipients[1-n], and
DiskFileUpload fu = new DiskFileUpload();
// If file size exceeds, a FileUploadException will be thrown
fu.setSizeMax(104857600);
File []attachments= null;
List fileItems = fu.parseRequest(request);
Iterator itr = fileItems.iterator();
int i = 0;
while (it.hasNext()) { // loop for how many different should go out depending on email addresses ...don't bother
while(itr.hasNext()) {
FileItem fi = (FileItem)itr.next();
if(!fi.isFormField()) {
String filename = fi.getName(); // gets the name of the files into a string. i've many files as such.
//////so here i need a logic to attach all the files available and also sid, cid, msg[1] for first time loop and add only one recipient from recipients[1] list and send him email
}
}
}// end of while (it.hasNext())
How do i do this...
I know we can attach multiple files.....in this manner
File[] attachments=new File{" " ," "," "}
attachments contains the list pof file to be attached.
for( int i = 0; i < attachments.length; i++ )
{
messageBodyPart = new MimeBodyPart();
FileDataSource fileDataSource =new FileDataSource(attachments [i]);
messageBodyPart.setDataHan dler(new DataHandler(fileDataSource ));
messageBodyPart.setFileNam e(attachme nts[i].get Name());
multipart.addBodyPart(mess ageBodyPar t);
}
// found at https://www.experts-exchange.com/questions/10805301/Multiple-Attachments-using-JavaMail-API.html?query=javamail+with+attachments&clearTAFilter=true
please help out with this...
Please help to frame....
I've SID, CID, MSG[1-n], String recipients[1-n], and
DiskFileUpload fu = new DiskFileUpload();
// If file size exceeds, a FileUploadException will be thrown
fu.setSizeMax(104857600);
File []attachments= null;
List fileItems = fu.parseRequest(request);
Iterator itr = fileItems.iterator();
int i = 0;
while (it.hasNext()) { // loop for how many different should go out depending on email addresses ...don't bother
while(itr.hasNext()) {
FileItem fi = (FileItem)itr.next();
if(!fi.isFormField()) {
String filename = fi.getName(); // gets the name of the files into a string. i've many files as such.
//////so here i need a logic to attach all the files available and also sid, cid, msg[1] for first time loop and add only one recipient from recipients[1] list and send him email
}
}
}// end of while (it.hasNext())
How do i do this...
I know we can attach multiple files.....in this manner
File[] attachments=new File{" " ," "," "}
attachments contains the list pof file to be attached.
for( int i = 0; i < attachments.length; i++ )
{
messageBodyPart = new MimeBodyPart();
FileDataSource fileDataSource =new FileDataSource(attachments
messageBodyPart.setDataHan
messageBodyPart.setFileNam
multipart.addBodyPart(mess
}
// found at https://www.experts-exchange.com/questions/10805301/Multiple-Attachments-using-JavaMail-API.html?query=javamail+with+attachments&clearTAFilter=true
please help out with this...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Sorry the baove loop should be like
BodyPart messageBody = new MimeBodyPart();
multiPart.addBodyPart(mess ageBody);
// Now the loop to n
for(i=0 to n)
Create new MimeMessage
Do not Create new MessageBody, use existin messageBody (Do not do a new)
Set recipent as recipent[i]
Set message as message[i]
mimeMessage.setContent(mul tiPart);
Send Mail
BodyPart messageBody = new MimeBodyPart();
multiPart.addBodyPart(mess
// Now the loop to n
for(i=0 to n)
Create new MimeMessage
Do not Create new MessageBody, use existin messageBody (Do not do a new)
Set recipent as recipent[i]
Set message as message[i]
mimeMessage.setContent(mul
Send Mail
for each mail message you have to send
a) SID
b) CID
c) Reipent[i] .. only one recipent to send mail to
d) Message[i] to be attached with ith mail.
Am I right here ?
Do you want to add all attachments to all mails or ith Attachment to ith mail ?