Link to home
Start Free TrialLog in
Avatar of Jagadeesh M
Jagadeesh MFlag for United States of America

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.setDataHandler(new DataHandler(fileDataSource));
    messageBodyPart.setFileName(attachments[i].getName());
           
    multipart.addBodyPart(messageBodyPart);
}

// 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...


 
Avatar of mrigank
mrigank

You have to send n mail messages

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 ?

ASKER CERTIFIED SOLUTION
Avatar of mrigank
mrigank

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Sorry the baove loop should be like

BodyPart messageBody = new MimeBodyPart();
multiPart.addBodyPart(messageBody);
// 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(multiPart);
Send Mail