URGENT : Multiple Attachments using JavaMail

Hello ,
I'm trying to send multiple attachments to a single mailid. I have 3 text boxes in my JSP page which holds the file name that is selected . in the next page i retrieving the values of those filenames and sending it as attachment .
But when i do so , i'm getting NullPointeException when one of 2 file is choose . but when i choose 3 files to send , it is working fine . Can any one help pls,
Here is the code
public class Attachservlet extends HttpServlet{
     public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException{
     String host="172.30.1.35";
     String full[]=new String[3];
     String part[]=new String[3];
     String fname[]=new String[3];
     String pname[]=new String[3];
     String ss[]=new String[3];
     String name[]=new String[3],conc="";
     int j,jj;
     String sender_email=req.getParameter("senderemail");
     String sender_name=req.getParameter("sendername");
     String receiver_email=req.getParameter("receiveremail");
     String receiver_name=req.getParameter("receivername");
     String sent_message=req.getParameter("area");
     PrintWriter out=res.getWriter();
     Properties props=System.getProperties();
     props.put("mail.smtp.host",host);
     Session session=Session.getDefaultInstance(props,null);
     MimeMessage message=new MimeMessage(session);
     try{
     for ( jj=0;jj<3;jj++){
     j=jj+1;
     name[jj]="filename"+j;
     pname[jj]="pname"+j;
     ss[jj]=req.getParameter(name[jj]);
     part[jj]=req.getParameter(pname[jj]);
     if(ss[jj].length()!=0){
     System.out.println("values is "+ss[jj] +"\n"+part[jj]);
     System.out.println("values is "+ss[jj] +"\n"+part[jj]);
     conc=conc+ss[jj]+",";
     System.out.println(conc);     
     message.setFrom(new InternetAddress(sender_email,"Sumathi"));
     message.addRecipient(Message.RecipientType.TO,new InternetAddress(receiver_email));
     message.setSubject(receiver_name);
     BodyPart bodypart=new MimeBodyPart();
     bodypart.setText(sent_message);
     Multipart multi=new MimeMultipart();
     multi.addBodyPart(bodypart);
     bodypart = new MimeBodyPart();
     DataSource source=new FileDataSource("test.jsp");
     bodypart.setDataHandler(new DataHandler(source));
     bodypart.setFileName(part[jj]);
     multi.addBodyPart(bodypart);
     message.setContent(multi);
     Transport.send(message);
     res.sendRedirect("http://sumathi/Mail/Success.jsp");
     System.out.println("Message Sent");
     }catch(Exception e){
     System.err.println("An Exception has Arrised \t"+e);
     public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{
     doPost(req,res);
Any Help pls ,
Thanks in Advance !

OK,
Although you didn't post the stack trace from your NullPointer, my guess is that it's being thrown at this line:
if(ss[jj].length()!=0){
your ss[jj] variable is being assigned the value: req.getParameter(name[jj]); This value is null in the case when you have anything less that 3 parameters in your form.
You need to check for a null value at this point.

Similar Messages

  • Sending Attachments using JavaMail

    I trying to send attachments using JavaMail API which is loaded into an oracle 8.1.7 database as a stored procedure, the code looks like this:-
    CREATE OR REPLACE AND COMPILE JAVA SOURCE NAMED "SendMail" AS
    import java.util.*;
    import java.io.*;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    public class SendMail {
    // Sender, Recipient, CCRecipient, and BccRecipient are comma-
    // separated lists of addresses;
    // Body can span multiple CR/LF-separated lines;
    // Attachments is a ///-separated list of file names;
    public static int Send(String SMTPServer,
    String Sender,
    String Recipient,
    String CcRecipient,
    String BccRecipient,
    String Subject,
    String Body,
    String ErrorMessage[],
    String Attachments) {
    // Error status;
    int ErrorStatus = 0;
    // create some properties and get the default Session;
    Properties props = System.getProperties();
    props.put("mail.smtp.host", SMTPServer);
    Session session = Session.getDefaultInstance(props, null);
    try {
    // create a message;
    MimeMessage msg = new MimeMessage(session);
    // extracts the senders and adds them to the message;
    // Sender is a comma-separated list of e-mail addresses as
    // per RFC822;
    InternetAddress[] TheAddresses =
    InternetAddress.parse(Sender);
    msg.addFrom(TheAddresses);
    // extract the recipients and assign them to the message;
    // Recipient is a comma-separated list of e-mail addresses
    // as per RFC822;
    InternetAddress[] TheAddresses =
    InternetAddress.parse(Recipient);
    msg.addRecipients(Message.RecipientType.TO,
    TheAddresses);
    // extract the Cc-recipients and assign them to the
    // message;
    // CcRecipient is a comma-separated list of e-mail
    // addresses as per RFC822;
    if (null != CcRecipient) {
    InternetAddress[] TheAddresses =
    InternetAddress.parse(CcRecipient);
    msg.addRecipients(Message.RecipientType.CC,
    TheAddresses);
    // extract the Bcc-recipients and assign them to the
    // message;
    // BccRecipient is a comma-separated list of e-mail
    // addresses as per RFC822;
    if (null != BccRecipient) {
    InternetAddress[] TheAddresses =
    InternetAddress.parse(BccRecipient);
    msg.addRecipients(Message.RecipientType.BCC,
    TheAddresses);
    // subject field;
    msg.setSubject(Subject);
    // create the Multipart to be added the parts to;
    Multipart mp = new MimeMultipart();
    // create and fill the first message part;
    MimeBodyPart mbp = new MimeBodyPart();
    mbp.setText(Body);
    // attach the part to the multipart;
    mp.addBodyPart(mbp);
    // attach the files to the message;
    if (null != Attachments) {
    int StartIndex = 0, PosIndex = 0;
    while (-1 != (PosIndex = Attachments.indexOf("///",
    StartIndex))) {
    // create and fill other message parts;
    MimeBodyPart mbp = new MimeBodyPart();
    FileDataSource fds =
    new FileDataSource(Attachments.substring(StartIndex,
    PosIndex));
    mbp.setDataHandler(new DataHandler(fds));
    mbp.setFileName(fds.getName());
    mp.addBodyPart(mbp);
    PosIndex += 3;
    StartIndex = PosIndex;
    // last, or only, attachment file;
    if (StartIndex < Attachments.length()) {
    MimeBodyPart mbp = new MimeBodyPart();
    FileDataSource fds =
    new FileDataSource(Attachments.substring(StartIndex));
    mbp.setDataHandler(new DataHandler(fds));
    mbp.setFileName(fds.getName());
    mp.addBodyPart(mbp);
    // add the Multipart to the message;
    msg.setContent(mp);
    // set the Date: header;
    msg.setSentDate(new Date());
    // send the message;
    Transport.send(msg);
    } catch (MessagingException MsgException) {
    ErrorMessage[0] = MsgException.toString();
    Exception TheException = null;
    if ((TheException = MsgException.getNextException()) !=
    null)
    ErrorMessage[0] = ErrorMessage[0] + "\n" +
    TheException.toString();
    ErrorStatus = 1;
    return ErrorStatus;
    show errors java source "SendMail"
    CREATE OR REPLACE PACKAGE SendMailJPkg AS
    -- EOL is used to separate text line in the message body;
    EOL CONSTANT STRING(2) := CHR(13) || CHR(10);
    TYPE ATTACHMENTS_LIST IS
    TABLE OF VARCHAR2(4000);
    -- high-level interface with collections;
    FUNCTION SendMail(SMTPServerName IN STRING,
    Sender IN STRING,
    Recipient IN STRING,
    CcRecipient IN STRING DEFAULT '',
    BccRecipient IN STRING DEFAULT '',
    Subject IN STRING DEFAULT '',
    Body IN STRING DEFAULT '',
    ErrorMessage OUT STRING,
    Attachments IN ATTACHMENTS_LIST DEFAULT NULL)
    RETURN NUMBER;
    END SendMailJPkg;
    show errors
    CREATE OR REPLACE PACKAGE BODY SendMailJPkg AS
    PROCEDURE ParseAttachment(Attachments IN ATTACHMENTS_LIST,
    AttachmentList OUT VARCHAR2) IS
    AttachmentSeparator CONSTANT VARCHAR2(12) := '///';
    BEGIN
    -- boolean short-circuit is used here;
    IF Attachments IS NOT NULL AND Attachments.COUNT > 0 THEN
    AttachmentList := Attachments(Attachments.FIRST);
    -- scan the collection, skip first element since it has been
    -- already processed;
    -- accommodate for sparse collections;
    FOR I IN Attachments.NEXT(Attachments.FIRST) ..
    Attachments.LAST LOOP
    AttachmentList := AttachmentList || AttachmentSeparator ||
    Attachments(I);
    END LOOP;
    ELSE
    AttachmentList := '';
    END IF;
    END ParseAttachment;
    -- forward declaration;
    FUNCTION JSendMail(SMTPServerName IN STRING,
    Sender IN STRING,
    Recipient IN STRING,
    CcRecipient IN STRING,
    BccRecipient IN STRING,
    Subject IN STRING,
    Body IN STRING,
    ErrorMessage OUT STRING,
    Attachments IN STRING) RETURN NUMBER;
    -- high-level interface with collections;
    FUNCTION SendMail(SMTPServerName IN STRING,
    Sender IN STRING,
    Recipient IN STRING,
    CcRecipient IN STRING,
    BccRecipient IN STRING,
    Subject IN STRING,
    Body IN STRING,
    ErrorMessage OUT STRING,
    Attachments IN ATTACHMENTS_LIST) RETURN NUMBER IS
    AttachmentList VARCHAR2(4000) := '';
    AttachmentTypeList VARCHAR2(2000) := '';
    BEGIN
    ParseAttachment(Attachments,
    AttachmentList);
    RETURN JSendMail(SMTPServerName,
    Sender,
    Recipient,
    CcRecipient,
    BccRecipient,
    Subject,
    Body,
    ErrorMessage,
    AttachmentList);
    END SendMail;
    -- JSendMail's body is the java function SendMail.Send();
    -- thus, no PL/SQL implementation is needed;
    FUNCTION JSendMail(SMTPServerName IN STRING,
    Sender IN STRING,
    Recipient IN STRING,
    CcRecipient IN STRING,
    BccRecipient IN STRING,
    Subject IN STRING,
    Body IN STRING,
    ErrorMessage OUT STRING,
    Attachments IN STRING) RETURN NUMBER IS
    LANGUAGE JAVA
    NAME 'SendMail.Send(java.lang.String,
    java.lang.String,
    java.lang.String,
    java.lang.String,
    java.lang.String,
    java.lang.String,
    java.lang.String,
    java.lang.String[],
    java.lang.String) return int';
    END SendMailJPkg;
    show errors
    var ErrorMessage VARCHAR2(4000);
    var ErrorStatus NUMBER;
    -- enable SQL*PLUS output;
    SET SERVEROUTPUT ON
    -- redirect java output into SQL*PLUS buffer;
    exec dbms_java.set_output(5000);
    BEGIN
    :ErrorStatus := SendMailJPkg.SendMail(
    SMTPServerName => 'gmsmtp03.oraclecorp.com',
    Sender => '[email protected]',
    Recipient => '[email protected]',
    CcRecipient => '',
    BccRecipient => '',
    Subject => 'This is the subject line: Test JavaMail',
    Body => 'This is the body: Hello, this is a test' ||
    SendMailJPkg.EOL || 'that spans 2 lines',
    ErrorMessage => :ErrorMessage,
    Attachments => SendMailJPkg.ATTACHMENTS_LIST(
    '/tmp/on.lst',
    '/tmp/sqlnet.log.Z'
    END;
    print
    If I try and send file as attachments from the tmp directory, then everything works ok, but if I try to send the same file from any other directory, then it doesn't work. Can anyone help? Is there something wrong with the code, I'm not aware of anything that would make it directory specfic. Permissions are the same on /tmp as the new directory /NRS/Data/SystemX which I'm trying to send the file from now.

    well
    if u see the end of ur mail it shows the attachment dir there in which u have specified the address..why don't u do a change there or better have some in parameteres in the procedure for it..that would help in choosing the attachment directory on users wish?
    hope i am getting the problem right..if not kindly correct me in understanding the problem.
    thanX.

  • Send email with multiple attachments using MS outlook

    Hi,
    Is it possible to send an email with multiple attachments using MS outlook. (Using activex)
    Regards,
    Neha

    nehrnul wrote:
    Hey thanks for the reply. I'll try that way also.
    but currently my requirement is to send email using MS Outlook. And I found 1 solution using invoke node
    Regards,
    Neha
    That' "requirement" sounds like it was written by someone who is trying to drive the design of the application.  Without knowing your personal situation it's hard for me to say, but if I had to guess I would say the real requirement is to send an email with multiple attachements, and the person giving that requirement thought sending it through Outlook would be the best way.  You should get clairification on what the real intend of that requirement is.
    Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
    If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously.

  • How can I send multiple attachments using SO_DYNP_OBJECT_SEND?

    Hi,
    I hope someone can offer advice on my problem.
    My requirement is to allow users to select one or more documents from an ALV grid.  I am then required to send these documents to multiple users via email using function module SO_DYNP_OBJECT_SEND.
    I can successfully send one document as an attachment.  However, I can't seem to figure out how to send multiple documents as attachments using SO_DYNP_OBJECT_SEND.  Is this done in the packing list?
    Is there some way to tell the program where the 1st attachment ends and the 2nd attachment starts?
    My attachment content is in i_att_cont.
      CALL FUNCTION 'SO_DYNP_OBJECT_SEND'
        EXPORTING
          object_hd_change = l_title
          object_type      = 'RAW'
          raw_editor       = abap_true
          starting_at_x    = '5'
          starting_at_y    = '1'
          ending_at_x      = '120'
          ending_at_y      = '20'
          edit_title       = 'X'
          external_commit  = abap_true
        TABLES
          objcont          = i_objcont
          rec_tab          = i_rec_tab
          packing_list     = i_packing_list
          att_cont         = i_att_cont
          exclude_fcode    = i_exclude_fcode
        EXCEPTIONS
          object_not_sent  = 1
          owner_not_exist  = 2
          parameter_error  = 3
          OTHERS           = 4.
    If you require more information, please let me know.  I will be happy to provide it.
    Thanks.

    I finally found the solution.
    The trick is to ensure you put the correct values in the body_start, body_num and objlen fields of the packing list.
    Each additional attachment should start (body_start) at the end of the last attachment + 1.
    The value for body_num is equal to the number of lines in the attachment being added.
    And the objlen field is calculated by multiplying the number of lines in the attachent * 255.
    Static data
       gs_packing_list-file_ext = lv_ext.
       gs_packing_list-transf_bin = 'X'.
       gs_packing_list-objla = sy-langu.
       gs_packing_list-objtp = 'EXT'.
       gs_packing_list-objdes = lv_filename.
       gs_packing_list-objnam = 'Attachment'.
       gs_packing_list-head_start = 1.
       gs_packing_list-head_num = 1.
    Body Start
       CLEAR lv_count.
       DESCRIBE TABLE gt_temp_att_cont LINES lv_count.
       gs_packing_list-body_start = lv_count + 1.
    Body Num + Object Length
       CLEAR lv_count.
       DESCRIBE TABLE gt_att_cont LINES lv_count.
       gs_packing_list-body_num = lv_count.
       gs_packing_list-objlen = lv_count * 255.
       APPEND gs_packing_list TO gt_packing_list.
    Hopefully this helps some desperate soul in the future.

  • Gettting attachments using JAVAMAIL

    Hi,
    I am dealing with an application which wants me to go through the mailbox and get the attachments of specific emails. These attachments are of different kinds. The attachments can vary from being rtf document, to Word, html, fo.. documents.. I got this skeleton code from the tutorial but dont know what to fill in..
    if (disposition == null) {
    // Check if plain
    MimeBodyPart mbp = (MimeBodyPart)part;
    if (mbp.isMimeType("text/plain")) {
    // Handle plain
    } else {
    // Special non-attachment cases here of
    // image/gif, text/html, ...
    What is it meant by handling plain? How do i handle html, worf, rtf documents.. Thanks a lot in advance.. Thanks
    Abhishek

    Try this as a reference. It works PERFECTLY. Ignore the comments.
    //If the content is ATTACHMENT
    filename = part.getFileName();
    if (filename != null) {
    filename = filename.trim();
    if(filename.equalsIgnoreCase(fileNameDownload.trim())) {
                                            //System.out.println("Downloading DOWN 1");
                                            session_id = this.DL_sessionid;
                                            directory = ATTACHMENTPath + m_user + "_" + session_id + "/";
                                            if(download) {
                                                 pushFile(part.getFileName(),part.getInputStream(),resp);
                                            } else {
                                                 saveFile(part.getFileName(), directory, part.getInputStream(), resp);
                                       filectr++;
         private void saveFile(String fileName, String Directory, InputStream input, HttpServletResponse resp)
              String myfile="";
              try
                   //Correct the file name;
                   String p_filename = javaFileParser(fileName);
                   File newDir = new File(Directory);
                   //Check if the directory does not exists!
                   if(!newDir.exists()) { //If it doesn't..
                        //Create the directory
                        newDir.mkdir();
                   String complete_path = Directory + p_filename;
                   File myFile=new File(complete_path);
                   //Check if a filename like this already exists!
                   if(myFile.exists()) {
                        //If it does..
                        //delete the current file residing into the directory
                        myFile.delete();
                   //Write the file (START)
                   FileOutputStream fos = new FileOutputStream(myFile);
                   BufferedOutputStream bos = new BufferedOutputStream(fos);
                   BufferedInputStream bis = new BufferedInputStream(input);
                   int aByte;
                   while ((aByte = bis.read()) != -1)
                   bos.write(aByte);
                   bos.flush();
                   bos.close();
                   bis.close();
                   //(END)
              catch (Exception x)
                   System.out.println("Error : " + x);
         private void pushFile(String fileName,InputStream input, HttpServletResponse resp)
              try
                   //Download the file to the Client's machine
                   ServletOutputStream stream = resp.getOutputStream();
                   resp.setContentType("application/octet-stream");
                   resp.setHeader("Content-Disposition","attachment;filename="+fileName.trim()+";");
                   //BufferedInputStream fif = new BufferedInputStream(new FileInputStream(complete_path));
                   BufferedInputStream fif = new BufferedInputStream(input);
                   int data;
                   while((data = fif.read()) != -1)
                   stream.write(data);
                   stream.flush();
                   fif.close();
                   stream.close();
              catch (Exception x)
                   System.out.println("Error : " + x);
         private String javaFileParser(String filename)
              //System.out.println("In EmailObject javaFileParser");
              String n_filename="";
              //Check if the file starts with '=?iso8859'
              //If it does, it will need parsing
              if(filename.startsWith("=?iso")) {
                   n_filename = filename.substring(15,filename.lastIndexOf("?"));
              } else
                   n_filename = filename;
              return n_filename;
    I suggest don't use JavaMail.. It has BUGS on some other email type. If not in POP3 then in IMAP.. Specialy when it receives "Enriched" contents types. Better yet don't use Java. It has lots of Bugs.

  • Send/Receive multiple attachments using SwA (no MTOM)

    Hello all,
    I would appreciate if someone can put me in the right direction about the following implementation:
    - web service method able to receive multiple attachment using weblogic tools (wsdlc, jwsc) without MTOM.
    I tried JAXRPC and JAXWS, starting from code and from wsdl, using bytearrayholder, DataHandler array ... without success.
    Better solution for my own goal would be using JAXRPC and Array of attachments.
    Actually I don't know what I can add again: I've done multiple tests and I cannot add all the used code/wsdl/build/... of course.
    I'm using WLS 10.0 (p3)
    I'm just a bit confused! So, I will thank if someone can suggest the right road and, in case, I'll post more details about the related test I've done.
    Thanks,
    Pepe

    Hello all,
    I would appreciate if someone can put me in the right direction about the following implementation:
    - web service method able to receive multiple attachment using weblogic tools (wsdlc, jwsc) without MTOM.
    I tried JAXRPC and JAXWS, starting from code and from wsdl, using bytearrayholder, DataHandler array ... without success.
    Better solution for my own goal would be using JAXRPC and Array of attachments.
    Actually I don't know what I can add again: I've done multiple tests and I cannot add all the used code/wsdl/build/... of course.
    I'm using WLS 10.0 (p3)
    I'm just a bit confused! So, I will thank if someone can suggest the right road and, in case, I'll post more details about the related test I've done.
    Thanks,
    Pepe

  • Parsing email attachments using Javamail

    Hi All,
    I'm working on a multimedia application where I have to parse emails using Javamail.
    Here is a problem that i'm facing.
    When i'm receiving an attachment from icloud.com, i'm not able to get the filename whereas i'm able to get the fileSize and fileContent.
    I'm using Part.getFileName() to get the file name. and Part.getFileSize() and Part.getInputStream() to get size and the content.
    When i checked the attachment header, I could see the name encoded in ISO-8859-1.
    --Boundary_(ID_kS5Ng+OB35IVBfC+scPoMA)
    Content-id:[email protected]
    Content-type:image/jpeg;
    name*1*=utf-8"%20%32%33%30%32%32%30%31%33%37%32%35;
    name*2*=%2E%6A%70%67
    Content-transfer-encoding:BASE64
    Content-disposition:inline;
    filename*1*=utf-8"%20%32%33%30%32%32%%30%32%33%37%32%35
    filename*2*=%2E%6A%70%67
    In both the cases above, Part.getFileName() is returning null.
    I set the parameter mail.mime.decodeparameters="true".Still it is not working.
    It would be great if someone can suggest a solution for this.
    Thanks
    Shyama

    Just adding to the problem description:
    --Boundary_(ID_kzWHPgILjZtH2UtdriatGg)
    Content-id: <[email protected]>
    Content-type: image/jpeg; name*1*=ISO-8859-1''%32%2E%6A%70%67
    Content-transfer-encoding: BASE64
    Content-disposition: inline; filename*1*=ISO-8859-1''%32%2E%6A%70%67
    This is the header which could see in another mail.

  • Redwood Cronacle: multiple attachments using rwmail

    How can I get my script to send multiple files as attachments to a single email using rwmail, or is it even possible? If possible, what is the syntax?

    I had tried that, but it looks like I just had the script formatted wrong for Windows. It works now. Thanks!

  • Multiple attachments using UTL_MAIL?

    Hi all,
    Does anyone know if its possible to attach multiple documents to an email and send them using the UTL_MAIL package. I am able to send one attachment stored in the server but would like to attach multiple files if possible. Any help would be greatly appreciated.
    Regards,
    Ray

    Hi all,
    Does anyone know if its possible to attach multiple documents to an email and send them using the UTL_MAIL package. I am able to send one attachment stored in the server but would like to attach multiple files if possible. Any help would be greatly appreciated.
    Regards,
    Ray

  • Multiple attachment using SO_NEW_DOCUMENT_ATT_SEND_API1

    HI geeks,
              Can anyone pls tell me how to attach multiple files using function module SO_NEW_DOCUMENT_ATT_SEND_API1.
              I have seen example of multiple attachments using same file type.I mean 1 or more files are same type like PDF or Excel.
              But my requirement is i have to send multiple attachment,1 file as PDF and other three excel file.
              Can anyone pls let me know,if anyone done this already,
    Thanks in advance
    Srini.

    Hi Srinivasn,
    Please see the below code u need to follow.  In the object pack table u might specified the number of lines per each attachement.  At the same time u need to specify the document type as  PDF  or XLS.  Please see the below code which is wrote for two attachments as xls.  In your case one attachment should be PDF.  This can be specified in the field
    LT_OBJPACK-DOC_TYPE = 'PDF'.
    IF NOT LT_ATT_TAB[] IS INITIAL AND
        NOT GV_ERR_REC IS INITIAL.        
        DESCRIBE TABLE LT_OBJBIN LINES LV_TAB_LINES.
        LV_TAB_LINES = LV_TAB_LINES - GV_SUC_REC.
        READ TABLE LT_OBJBIN INDEX LV_TAB_LINES.
        LT_OBJPACK-DOC_SIZE =
       ( LV_TAB_LINES - 1 ) * 255 + STRLEN( LT_OBJBIN ).
        LT_OBJPACK-TRANSF_BIN = 'X'.
        LT_OBJPACK-HEAD_START = 1.
        LT_OBJPACK-HEAD_NUM = 0.
        LT_OBJPACK-BODY_START = 1.
        LT_OBJPACK-BODY_NUM = LV_TAB_LINES.
        LT_OBJPACK-DOC_TYPE = LC_XLS.
        LT_OBJPACK-OBJ_NAME = 'ATTACHMENT'.
        LT_OBJPACK-OBJ_DESCR = LV_ATTACH_NAME2(50).
        APPEND LT_OBJPACK.
      ENDIF.                               " IF NOT lt_att_tab[] IS ...
    File2 attachment for processed records.
      IF NOT LT_ATT_TAB[] IS INITIAL AND
         NOT GV_SUC_REC IS INITIAL.
        CLEAR LT_OBJPACK.
        DESCRIBE TABLE LT_OBJBIN LINES LV_TAB_LINES.
        LV_TAB_LINES = LV_TAB_LINES - GV_ERR_REC.
        GV_ERR_REC = GV_ERR_REC + 1.
        READ TABLE LT_OBJBIN INDEX LV_TAB_LINES.
        LT_OBJPACK-DOC_SIZE =
       ( LV_TAB_LINES - 1 ) * 255 + STRLEN( LT_OBJBIN ).
        LT_OBJPACK-TRANSF_BIN = 'X'.
        LT_OBJPACK-HEAD_START = GV_ERR_REC.
        LT_OBJPACK-HEAD_NUM   = 0.
        LT_OBJPACK-BODY_START = GV_ERR_REC.
        LT_OBJPACK-BODY_NUM   = LV_TAB_LINES.
        LT_OBJPACK-DOC_TYPE   = LC_XLS.
        LT_OBJPACK-OBJ_NAME   = 'ATTACHMENT'(009).
        LT_OBJPACK-OBJ_DESCR  = LV_ATTACH_NAME(50).
        APPEND LT_OBJPACK.
      ENDIF.                               " IF NOT lt_att_tab[] IS ...
    Thanks
    IF NOT LT_ATT_TAB[] IS INITIAL AND
        NOT GV_ERR_REC IS INITIAL.        
        DESCRIBE TABLE LT_OBJBIN LINES LV_TAB_LINES.
        LV_TAB_LINES = LV_TAB_LINES - GV_SUC_REC.
        READ TABLE LT_OBJBIN INDEX LV_TAB_LINES.
        LT_OBJPACK-DOC_SIZE =
       ( LV_TAB_LINES - 1 ) * 255 + STRLEN( LT_OBJBIN ).
        LT_OBJPACK-TRANSF_BIN = 'X'.
        LT_OBJPACK-HEAD_START = 1.
        LT_OBJPACK-HEAD_NUM = 0.
        LT_OBJPACK-BODY_START = 1.
        LT_OBJPACK-BODY_NUM = LV_TAB_LINES.
        LT_OBJPACK-DOC_TYPE = LC_XLS.
        LT_OBJPACK-OBJ_NAME = 'ATTACHMENT'.
        LT_OBJPACK-OBJ_DESCR = LV_ATTACH_NAME2(50).
        APPEND LT_OBJPACK.
      ENDIF.                               " IF NOT lt_att_tab[] IS ...
    File2 attachment for processed records.
      IF NOT LT_ATT_TAB[] IS INITIAL AND
         NOT GV_SUC_REC IS INITIAL.
        CLEAR LT_OBJPACK.
        DESCRIBE TABLE LT_OBJBIN LINES LV_TAB_LINES.
        LV_TAB_LINES = LV_TAB_LINES - GV_ERR_REC.
        GV_ERR_REC = GV_ERR_REC + 1.
        READ TABLE LT_OBJBIN INDEX LV_TAB_LINES.
        LT_OBJPACK-DOC_SIZE =
       ( LV_TAB_LINES - 1 ) * 255 + STRLEN( LT_OBJBIN ).
        LT_OBJPACK-TRANSF_BIN = 'X'.
        LT_OBJPACK-HEAD_START = GV_ERR_REC.
        LT_OBJPACK-HEAD_NUM   = 0.
        LT_OBJPACK-BODY_START = GV_ERR_REC.
        LT_OBJPACK-BODY_NUM   = LV_TAB_LINES.
        LT_OBJPACK-DOC_TYPE   = LC_XLS.
        LT_OBJPACK-OBJ_NAME   = 'ATTACHMENT'(009).
        LT_OBJPACK-OBJ_DESCR  = LV_ATTACH_NAME(50).
        APPEND LT_OBJPACK.
      ENDIF.                               " IF NOT lt_att_tab[] IS ...
    Venkat

  • How to send multiple attachments?

    Sorry if this seems like an obvious question but can it be done? Do I need an extra app or helper?
    Thanks in advance

    Ernie,
    I have had problems with sending some attachments to windows users.
    i cant tell exactly what is causing it.
    usually i am making .pages documents which i then export as PDFs.
    many times windows users email me back that they cant even see the attached PDFs (not not open them, but cant even see them).
    there seems to be some sort of bug. (yes, attach as windows friendly documents is selected).
    some have suggested that attaching multiple attachments using the command click method might be at fault.
    others have suggested that exporting to pdf might be a problem and the resulting pdf not always readable by windows users.
    can you give any suggestion that might ensure windows users can always open my attached PDFs?
    thanks

  • Problem with sending large HTML files as attachment using JavaMail 1.2

    Hi dear fellows, i am currently working on posting Emails with attachments using JavaMail 1.2. i succeeded in sending many mimetypes of files as attachments except for .htm and .html files. when large HTML files (say, >100 kB) serve as attachements, the mail is posted on mail server, but not properly posted since only the first small part of the file is writted into mail server but the latter part of the attachment file is missing.
    is that a bug of JavaMail??? are there any fellows encountering similar problem as i did??? any suggestions for me to proceed? hopefully i made myself clear...
    Many thanks in advance,
    Fatty

    i've sort of found the cause for that, it is because when the stream write to the mail server, unfortunately there is a "." in a single line. so the server refuse to take any more inputs.
    so do i have to remove all the "." in the file manually to avoid this disaster? any suggestions??
    Fatty

  • Iam unable to send multiple attachments with a mail using JavaMail?

    Hai to all,
    Iam unable to send multiple attachments with a email,see
    iam have succeeded in sending one attachment with a email.
    when iam tring to add two or more attachments to a mail,
    it is giving a Exception like this:
    javax.mail.MessagingException: IOException while sending message;
    nested exception is:
    java.io.IOException: No content
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:577)
    at javax.mail.Transport.send0(Transport.java:151)
    at javax.mail.Transport.send(Transport.java:80)
    at AttachFilesModified.sendMail(AttachFilesModified.java:185)
    at AttachFilesModified.main(AttachFilesModified.java:43)
    this is my code snipnet:
    BodyPart messageBodyPart = new MimeBodyPart();
    Multipart multipart = new MimeMultipart();
    if(body != null)
    messageBodyPart.setText(body);
    multipart.addBodyPart(messageBodyPart);
    /*if(attachments != null)
    for(int i = 0; i < attachments.length; i++)
    String filename="D:\\nagaraju\\apachi\\axis-bin-1_3.zip";
         //String s[]=filename.split("\\");
         //System.out.println(s);     
              //String s1=s[1];
              //String filename1=s[s.length-1];
    messageBodyPart = new MimeBodyPart();
    DataSource source = new FileDataSource(filename);
         messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName(filename);
    multipart.addBodyPart(messageBodyPart);
         //second file attaching
         /*String filename1="C:\\nagadoc.txt";
         BodyPart messageBodyPart1=new MimeBodyPart();
         DataSource source1=new FileDataSource(filename1);
         messageBodyPart.setDataHandler(new DataHandler(source1));
         messageBodyPart.setFileName(filename1);
         multipart.addBodyPart(messageBodyPart1);
    mess.setContent(multipart);
    Address[] allRecips = mess.getAllRecipients();
    if(toStdOut)
    System.out.println("done.");
    //System.out.println("Sending message (\"" + mess.getSubject().substring(0,10) + "...\") to :");
    System.out.println("Sending message................");
    for(int i = 0; i < allRecips.length; i++)
    System.out.print(allRecips[i] + ";");
    System.out.println("...");
    Transport.send(mess);
    if(toStdOut)
    System.out.println("done.");
    return 0;
    What's wrng with that code snipnet?
    Nagaraju G.

    This works fine with me, try it or compare it if you want.
    public void sendEmail( String from, String to,
    String subject, String body) {
    fMailServerConfig.put("mail.smtp.host", " <<mail server>>");
    Session session = Session.getDefaultInstance( fMailServerConfig, null );
    MimeMessage message = new MimeMessage( session );
    try {
    message.setFrom(new InternetAddress(from));
    message.setRecipient(Message.RecipientType.TO,
    new InternetAddress(to));
    message.setSubject( subject);
    message.setText( body);
    //Adds Attechment:
    Multipart multipart = new MimeMultipart();
    BodyPart messageBodyPart = new MimeBodyPart();
    messageBodyPart.setText("Here are my attachments");
    multipart.addBodyPart(messageBodyPart);
    messageBodyPart = new MimeBodyPart();
    //first attachment
    DataSource source = new FileDataSource("C:\\img1.jpg");
    messageBodyPart.setDataHandler(new DataHandler(source));
    messageBodyPart.setFileName("C:\\Telnor1.jpg");
    multipart.addBodyPart(messageBodyPart);
    //Second attachment
    DataSource source2 = new FileDataSource("C:\\img2.jpg");
    messageBodyPart.setDataHandler(new DataHandler(source2));
    messageBodyPart.setFileName("C:\\Telnor2.jpg");
    multipart.addBodyPart(messageBodyPart);
    //etc...
    message.setContent(multipart);
    Transport.send( message );
    }catch (MessagingException e){
    System.err.println("Cant send mail. " + e);
    The error on your code might be:
    BodyPart messageBodyPart1=new MimeBodyPart();
    DataSource source1=new FileDataSource(filename1);
    messageBodyPart.setDataHandler(new DataHandler(source1));
    messageBodyPart.setFileName(filename1);
    multipart.addBodyPart(messageBodyPart1);
    You don't need to create a new BodyPart, and apart from that you'r seting values on "messageBodyPart" but adding "messageBodyPart1" to your multipart :P
    Well see u and have a good one!
    p.s. i know it's a little late from the day you posted, but at least it might help somebody else :D .

  • Send multiple email attachments using FM SO_NEW_DOCUMENT_ATT_SEND_API1.How?

    Hi All,
    I have a requirement to send email to an external ID for which I am using FM SO_NEW_DOCUMENT_ATT_SEND_API1.Can anyone give a sample code to send multiple excel attachments using this function module.
    Points would be rewarded.
    Thanks
    Archana.

    Check the Thread,,
    Re: more than 1 attachements/sheets in SO_DOCUMENT_SEND_API1

  • Multiple attachments in single mail using XML publisher bursting

    Hi all
    I am sending the PDF generated to a particular mail recipient using the bursting options.
    There is requirement in which I have to attach two different PDF's to the mail. These multiple attachments should go in a single mail. Please let me know how we can achieve this.
    Thanks in adv,
    Srini
    Edited by: 796646 on Mar 4, 2011 2:35 PM

    Suresh,
    just copy your question and paste it in search box.. press enter
    there are too many posts already on this.
    still a little help for you, with explanation:
    [code snipet with documentation|http://wiki.sdn.sap.com/wiki/display/Snippets/MultipleAttachmentsExplanation]

Maybe you are looking for