Want to send PDF as attachement using Java Mail

HI,
I am using Java mail API for sending PDF as attachment. Here is my sample code
messageBodyPart = new MimeBodyPart();
messageBodyPart.setDataHandler(new DataHandler("String data for PDF using iText", "text/plain" ));
I am generating String for PDF file using iTEXT but I am unable to find out mimetype for passing into DataHandler as second paramete.
Any idea?
Thanks
Shailesh

Don't convert the data to String. It isn't text so
you'll damage the binary content by doing that. In
the "demos" directory of your JavaMail download
you'll find a ByteArrayDataSource class you can use
instead of a FileDataSource. Yes, this worked for me. I create the pdf in memory as as StringBuffer and I just changed the code from
messageBodyPart.setDataHandler(new DataHandler(pdf.toString(), "application/pdf"));
to
messageBodyPart.setDataHandler(new DataHandler(new ByteArrayDataSource(pdf.toString(), "application/pdf")));
and it worked.
Thanks a lot for your help,
Dennis

Similar Messages

  • How to Read An Attachment Using Java Mail

    Hi
    I Am Able To Read The Mail Using Java Mail ,but Unable To Read The Attachment Which Comes Along With The Mail.
    Please Help Me , In Reading The Attachment.

    Hi
    I Am Able To Read The Mail Using Java Mail ,but
    t Unable To Read The Attachment Which Comes Along
    With The Mail.
    Please Help Me , In Reading The Attachment.Do you mean:
    - I only recieve .txt or .doc attachments and I want to see the contents? Or could you get a .jpg as well?
    or
    - Do you need to seperate the attachment from the e-mail and then view it?

  • Extract Mail Attachment using Java Mail

    Hello Friends
    A day ago I entered into Java Mail , now I am able to send mail from my Java Program.
    The help I need from you is I wanna save the attachment coming in the mail using Java.
    For eg : a mail reched my Inbox contains .xls or .csv file which I wanna save to some place.
    Plss guide me to acheive this friends.
    Regards
    Vicky

    String host = "";
    String username = "";
    String password = "";
    String srcDir = "INBOX";
    String tarDir = "";
         String subject = "";
    String filepath = "C:/Documents and Settings/name/Desktop";
    String filename = "demo";
    Properties props = System.getProperties();
    props.put("mail.host", host);
    Session session = Session.getDefaultInstance(props, null);
    Store store = session.getStore("imap");
    store.connect(host, username, password);
    Folder folder = store.getFolder(srcDir);
              Folder dFolder = store.getFolder(tarDir);
    folder.open(Folder.READ_WRITE);
              Message message[] = folder.getMessages();
              java.util.Date yesterdayDate = new Date(System.currentTimeMillis() - 24*60*60*1000);
    for (int p = 0; p < message.length; p++) {
                   java.util.Date messageReceivedDate = message[p].getReceivedDate();
                   if(messageReceivedDate.after(yesterdayDate))
                        if (message[p].getSubject().equals(subject)) {
                             Multipart mp = (Multipart)(message[p].getContent());
                             for (int i = 0, n = mp.getCount(); i < n; i++) {
    Part part = mp.getBodyPart(i);
    String disposition = part.getDisposition();
    if ((disposition != null) && (disposition.equals("ATTACHMENT") || disposition.equals("INLINE")))) {
    String fullpath = filepath+"/" + filename+".csv";               
    File file = new File(fullpath);
    InputStream in = part.getInputStream();
    FileOutputStream fos = new FileOutputStream(file);
    byte[] buf = new byte[part.getSize()];
    int c = 0;
                             while ((c = in.read(buf)) != -1) {
    fos.write(buf, 0, c);
                                       in.close();
                                       fos.close();
                                  } // if (disposition) closing
                             }// inner for loop closing
    /* ----------------------------------------------------Move Message to new folder--------------------------------------------------------------------- */
    if (message.length != 0) {
    folder.copyMessages(message, dFolder);
    folder.setFlags(message, new Flags(Flags.Flag.DELETED), true);
    // Dump out the Flags of the moved messages, to insure that
    // all got deleted
    for (int i = 0; i < message.length; i++)
                                  if (!message.isSet(Flags.Flag.DELETED))
                                       System.out.println("Message # " + message[i] + " not deleted");
                             } //for
    }// if (message.length != 0)
    // System.out.println("*** Message moved to "+tarDir+" Directory ***");
                        }//if loop closing - checking message subject
                   }// if loop closing checking date
    }// outer for() loop closing

  • Sending PDF as attachment using Business workflow from Java WD

    Hi,
    It seems it is famous and known may be solved issue. But i am not able to conceptualize the information available. Thats why i am posting this. pls suggest me how to proceed.
    My scenario: I have an online intercative form in java webdynpro application where as once user completes data entry on send button click, i am triggereing an workflow of ECC6.0 which sends mail to MS exchange mail ID. Once user gets the form and complete comments section i have another application which allows user to upload the file which is similar to offline case. But  when i send the attachment i am getting mail with pdf attachment but when i open PDF i am getting error. And it seems PDF doesn't contain data(as size of pdf is 1 KB). and i tried to use xstring as input type.
    Can anyone pls guide me how to proceed.
    Regards
    Ravindra.

    A pdf file is definitely not a text file. Storing it in a Java String is a mistake.
    Is the "body" variable in your code a String? How does the data get into
    the String?

  • Send Mail with PDF as attachment using Simple mail Option to multiple addre

    Hi all,
    I have a requirement to send the form as attachment to the multiple addresses maintained.
    I want to know the procedure to retrieve all those addresses.
    I am aware of the complete procedure of getting the OTF and and converting to PDF and the sending using API function module.
    Please help me in getting the addresses.
    Regards,
    Vivek

    Hi,
    I use the following code to get all of the email addresses attached to a vendor...
    * Find the partners email address (this should be a vendor)
      select single adrnr into lv_adrnr
        from lfa1 where lifnr = nast-parnr.
      select smtp_addr flgdefault
             adr6~date_from adr6~consnumber remark into table lt_email
        from adr6
         left outer join adrt
            on  adrt~addrnumber = adr6~addrnumber
            and adrt~persnumber = adr6~persnumber
            and adrt~comm_type  = 'INT'
            and adrt~date_from  = adr6~date_from
            and adrt~consnumber = adr6~consnumber
          where adr6~addrnumber  = lv_adrnr
            and adr6~date_from  <= sy-datum
          order by adr6~date_from adr6~consnumber.
    Darren

  • Sending PDF as attachment using utl_smtp

    Hi all,
    I am encountering the following problem when i try to send the email using utl_smtp builtin,i receive the mail in my outlook,but not able to read the contents of the pdf file.
    Oracle Version :- Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    source code:-
    CREATE OR REPLACE PROCEDURE "PROC_MAIL_ATTACH_PDFS" (
    p_cust_nb IN cstm.cstm_cust_nb%TYPE,
    from_name IN VARCHAR2,
    to_name IN VARCHAR2,
    subject IN VARCHAR2,
    MESSAGE IN VARCHAR2,
    p_binary_file IN VARCHAR2,
    p_seq_id IN NUMBER,
    p_ret_cd OUT NUMBER,
    p_ret_desc OUT VARCHAR2
    --ISO-8859-6
    IS
    v_smtp_server VARCHAR2 (100) := '172.20.204.17';
    --change this to your mail server
    v_smtp_server_port NUMBER := 25;
    v_directory_name VARCHAR2 (100);
    v_file_name VARCHAR2 (100);
    v_line VARCHAR2 (1000);
    crlf VARCHAR2 (2) := CHR (13)
    || CHR (10);
    mesg VARCHAR2 (32767);
    conn UTL_SMTP.connection;
    v_slash_pos NUMBER;
    v_file_handle UTL_FILE.file_type;
    invalid_path EXCEPTION;
    mesg_length_exceeded BOOLEAN := FALSE;
    l_msg VARCHAR2 (32000);
    l_tag_sep VARCHAR2 (1)
    := func_get_config_value ('TAGSEPRTR');
    l_ind VARCHAR2 (10);
    l_rec VARCHAR2 (4000);
    l_sep_rep VARCHAR2 (4000) := '17_ACCSTMT_NOV_2010';
    l_rem_rep VARCHAR2 (4000);
    l_rep VARCHAR2 (4000);
    l_mim_type VARCHAR2 (2000);
    boundary CONSTANT VARCHAR2 (256)
    := '-----DMW.Boundary.605592468';
    first_boundary CONSTANT VARCHAR2 (256) := '--' || boundary || crlf;
    last_boundary CONSTANT VARCHAR2 (256)
    := '--' || boundary || '--' || crlf;
    multipart_mime_type CONSTANT VARCHAR2 (256)
    := 'multipart/mixed; boundary="' || boundary || '"';
    mime_type VARCHAR2 (255) := 'text/html';
    l_offset NUMBER;
    l_ammount NUMBER;
    CURSOR cur_trnm
    IS
    SELECT trnm_email_enarr, trnm_email_anarr
    FROM trnm
    WHERE trnm_id = 16;
    l_enarr trnm.trnm_email_enarr%TYPE;
    l_anarr trnm.trnm_email_enarr%TYPE;
    l_message_body VARCHAR2 (32000);
    --// To check if all mails belongs to the customer already sent...
    CURSOR cur_pdfd
    IS
    SELECT COUNT (*)
    FROM pdfd
    WHERE pdfd_cust_nb = p_cust_nb
    AND pdfd_email_sts IS NULL
    --NEWLY ADDED ...
    AND NVL (pdfd_stmt_mode, '.') = 'E'
    AND TRUNC (pdfd_to_dt) = (SELECT MAX (TRUNC (pdfd_to_dt))
    FROM pdfd
    WHERE pdfd_cust_nb = p_cust_nb);
    l_cnt NUMBER := 0;
    PROCEDURE send_header (NAME IN VARCHAR2, header IN VARCHAR2)
    IS
    BEGIN
    UTL_SMTP.write_data (conn, NAME || ': ' || header || crlf);
    END;
    PROCEDURE write_raw (
    p_conn IN OUT NOCOPY UTL_SMTP.connection,
    p_message IN RAW
    IS
    BEGIN
    UTL_SMTP.write_raw_data (p_conn, p_message);
    END write_raw;
    PROCEDURE binary_attachment (
    p_conn IN OUT UTL_SMTP.connection,
    p_file_name IN VARCHAR2,
    p_mime_type IN VARCHAR2
    IS
    k_max_line_width CONSTANT PLS_INTEGER DEFAULT 54;
    v_amt BINARY_INTEGER := 672 * 3;
    /* ensures proper format; 2016 */
    v_bfile BFILE;
    v_file_len PLS_INTEGER;
    v_buf RAW (2100);
    v_buf1 RAW (2100);
    v_modulo PLS_INTEGER;
    v_pieces PLS_INTEGER;
    v_file_pos PLS_INTEGER := 1;
    v_data RAW (32767);
    v_data1 RAW (32767);
    v_chunks PLS_INTEGER;
    l_amt NUMBER := 32767;
    l_off NUMBER := 1;
    l_raw RAW (32767);
    l_raw1 RAW (32767);
    l_lob BLOB;
    l_lob_empt BLOB;
    req UTL_HTTP.req;
    resp UTL_HTTP.resp;
    resp_empt UTL_HTTP.resp;
    l_url VARCHAR2 (4000);
    l_rep_path VARCHAR2 (2000);
    l_report VARCHAR2 (100);
    l_seq_nb repq.repq_seq_nb%TYPE;
    l_parm repq.repq_parm_val%TYPE;
    l_repq repq%ROWTYPE;
    l_sts NUMBER;
    l_user VARCHAR2 (10);
    --L_MSG VARCHAR2(32000);
    l_seq_id NUMBER;
    usr_err EXCEPTION;
    --// 07-Jun-2009 - Basheer A.S. : Code added for sending A/c Statement and PFL statements in single e-mail ...
    CURSOR cur_pdfd
    IS
    SELECT
    --UTL_COMPRESS.LZ_UNCOMPRESS(PDFD_DB_FILE) PDFD_DB_FILE,
    pdfd_file_name
    FROM pdfd
    WHERE pdfd_cust_nb = p_cust_nb
    --AND PDFD_EMAIL_STS IS NULL
    --NEWLY ADDED ...
    --AND NVL(PDFD_STMT_MODE,'.') = 'E'
    AND pdfd_seq_nb = p_seq_id
    AND TRUNC (pdfd_to_dt) = (SELECT MAX (TRUNC (pdfd_to_dt))
    FROM pdfd
    WHERE pdfd_cust_nb = p_cust_nb);
    l_buffer_size INTEGER := 57;
    l_offset INTEGER := 1;
    l_raw RAW (57);
    l_file_nm pdfd.pdfd_file_name%TYPE;
    BEGIN
    --// 06-Jun-2009 - Basheer A.S. : Code added for sending A/c Statement and PFL statements in a single e-mail ...
    --// Initializing temporary CLOB data ...
    DBMS_LOB.createtemporary (l_lob, FALSE);
    --DBMS_LOB.createtemporary(L_LOB_EMPT, FALSE);
    --// Loop thro all the records for the given Customer Number...
    OPEN cur_pdfd;
    LOOP
    --FETCH CUR_PDFD INTO L_LOB, L_FILE_NM;
    FETCH cur_pdfd
    INTO --L_LOB_EMPT,
    l_file_nm;
    EXIT WHEN cur_pdfd%NOTFOUND;
    proc_audit_log ('T',
    'PROC_MAIL_ATTACH_PDFS, Customer No. '
    || p_cust_nb
    || ', File attachment: '
    || l_file_nm
    UTL_SMTP.write_data (conn, first_boundary);
    UTL_SMTP.write_data (conn,
    'Content-Transfer-Encoding: base64 '
    || UTL_TCP.crlf
    UTL_SMTP.write_data (conn,
    'Content-Type: ' || mime_type || UTL_TCP.crlf
    UTL_SMTP.write_data (conn,
    'Content-Disposition: ATTACHMENT; filename="'
    || p_file_name
    || '"'
    || UTL_TCP.crlf
    UTL_SMTP.write_data (conn, crlf);
    l_ind := '1.1';
    v_file_pos := 1;
    --// Attaching individual PDF files ...
    BEGIN
    v_modulo := 0;
    v_pieces := 0;
    v_amt := 2016;
    l_ind := '2.1';
    v_file_len := DBMS_LOB.getlength (l_lob);
    --v_file_len := dbms_lob.getlength(L_LOB_EMPT);
    v_modulo := MOD (v_file_len, v_amt);
    v_pieces := TRUNC (v_file_len / v_amt);
    IF (v_modulo <> 0)
    THEN
    v_pieces := v_pieces + 1;
    END IF;
    l_ind := '2.2';
    DBMS_LOB.READ (l_lob, v_amt, v_file_pos, v_buf);
    --dbms_lob.read(L_LOB_EMPT, v_amt, v_file_pos, v_buf);
    v_data := v_data1;
    v_chunks := 0;
    v_data := v_data1;
    FOR i IN 1 .. v_pieces
    LOOP
    v_file_pos := i * v_amt + 1;
    v_file_len := v_file_len - v_amt;
    v_data := UTL_RAW.CONCAT (v_data, v_buf);
    l_ind := '2.3';
    v_chunks := TRUNC (UTL_RAW.LENGTH (v_data) / k_max_line_width);
    IF (i <> v_pieces)
    THEN
    v_chunks := v_chunks - 1;
    END IF;
    l_ind := '2.4';
    write_raw (p_conn => p_conn,
    p_message => UTL_ENCODE.base64_encode (v_data)
    v_data := v_data1;
    IF (v_file_len < v_amt AND v_file_len > 0)
    THEN
    v_amt := v_file_len;
    END IF;
    l_ind := '2.5';
    DBMS_LOB.READ (l_lob, v_amt, v_file_pos, v_buf);
    --DBMS_LOB.READ(L_LOB_EMPT, v_amt, v_file_pos, v_buf);
    END LOOP;
    EXCEPTION
    WHEN OTHERS
    THEN
    proc_audit_log
    ('E',
    'PROC_MAIL_ATTACH_PDFS.binary_attachment.inside BLOB loop, :'
    || SQLERRM
    || ',ind:'
    || l_ind
    END;
    v_file_pos := 1;
    UTL_SMTP.write_data (conn, UTL_TCP.crlf);
    UTL_SMTP.write_data (conn, UTL_TCP.crlf);
    END LOOP;
    --// END multiple file attachments
    l_ind := '2.6';
    UTL_SMTP.write_data (p_conn, last_boundary || UTL_TCP.crlf);
    EXCEPTION
    WHEN OTHERS
    THEN
    proc_audit_log ('E',
    'PROC_MAIL_ATTACH_PDFS, when others:'
    || l_ind
    || ', '
    || SQLERRM
    END binary_attachment;
    BEGIN
    --// If no pending emails for the given Customer, then exit the process...
    OPEN cur_pdfd;
    FETCH cur_pdfd
    INTO l_cnt;
    CLOSE cur_pdfd;
    --// If still pending statements needs to be send...
    --IF L_CNT > 0 THEN
    IF l_cnt = 0
    THEN
    OPEN cur_trnm;
    FETCH cur_trnm
    INTO l_enarr, l_anarr;
    CLOSE cur_trnm;
    l_message_body :=
    '<html>'
    ||
    --'<meta http-equiv="Content-Type" content="text/html; charset=WINDOWS-1256(Arabic)">'||
    --'<meta http-equiv="Content-Type" content="text/html; charset=WINDOWS-1256">'||
    '<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-6">'
    || '<body>
    <TABLE BORDER="0" WIDTH=100% style="table-layout:fixed;">
    <TR>
    <TD WIDTH="50%" ALIGN="LEFT" style="word-wrap: break-word"><B>'
    || l_enarr
    || '</B></TD>'
    || '<TD WIDTH="50%" ALIGN="RIGHT" style="word-wrap: break-word"><B>'
    || l_anarr
    || '</B></TD></TR></TABLE>
    </body>
    </html>';
    proc_audit_log ('T', 'PROC_MAIL_ATTACH_PDFS, msg:' || l_msg);
    v_smtp_server := func_get_config_value ('MAILHOST');
    v_smtp_server_port := func_get_config_value ('MAILPORT');
    l_ind := '3.1';
    conn := UTL_SMTP.open_connection (v_smtp_server, v_smtp_server_port);
    --utl_smtp.helo( conn, v_smtp_server );
    --utl_smtp.mail( conn, '[email protected]' );
    UTL_SMTP.helo (conn, v_smtp_server);
    UTL_SMTP.mail (conn, from_name);
    UTL_SMTP.rcpt (conn, to_name);
    l_ind := '3.2';
    l_rec := func_eti_tagval (l_msg, 'EMAIL');
    proc_audit_log ('T', 'PROC_MAIL_ATTACH_PDFS, l_rec:' || l_rec);
    proc_audit_log ('T', 'l_sep_rep1' || l_sep_rep);
    UTL_SMTP.open_data (conn);
    send_header ('From', '<' || from_name || '>');
    send_header ('To', '<' || to_name || '>');
    --send_header('To',''||Func_Eti_Tagval(L_MSG, 'EMAIL')||'');
    send_header ('Date', TO_CHAR (SYSDATE, 'dd Mon yy hh24:mi:ss'));
    send_header ('Subject', subject);
    send_header ('Content-Type', multipart_mime_type);
    UTL_SMTP.write_data (conn, first_boundary);
    --utl_smtp.write_data(conn, 'Content-Type: '||mime_type||utl_tcp.crlf);
    --utl_smtp.write_data(conn, 'Content-Type: '||mime_type||'; charset=Windows-1256'||utl_tcp.crlf);
    UTL_SMTP.write_data (conn,
    'Content-Type: '
    || mime_type
    || '; charset=ISO-8859-6'
    || UTL_TCP.crlf
    --new...
    UTL_SMTP.write_data (conn, crlf);
    UTL_SMTP.write_raw_data (conn, UTL_RAW.cast_to_raw (l_message_body));
    UTL_SMTP.write_data (conn, crlf);
    UTL_SMTP.write_data (conn, crlf);
    proc_audit_log ('T', 'l_sep_rep2' || l_sep_rep);
    binary_attachment (p_conn => conn,
    p_file_name => l_sep_rep || '.pdf',
    p_mime_type => 'multipart/mixed'
    ); --||l_sep_rep||'.pdf');
    UTL_SMTP.write_data (conn, last_boundary || UTL_TCP.crlf);
    UTL_SMTP.close_data (conn);
    UTL_SMTP.quit (conn);
    END IF;
    p_ret_cd := 0;
    p_ret_desc := 'Mail sent successfully';
    EXCEPTION
    WHEN OTHERS
    THEN
    proc_audit_log ('E',
    'PROC_MAIL_ATTACH_PDFS, error:'
    || SQLERRM
    || 'ind:'
    || l_ind
    p_ret_cd := 1;
    END;
    Kindly help me to resolve this issue.
    Thanks & Regards
    Ariff

    pl ease check below link
    /people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface

  • Sending PDF output attachment in e-mail to external users from BSP

    Hi All,
    Please gothrough the below requirement details :
    Requirement Details:
    Need to achieve the functionality of sending a PDF attachment of invoice to an external
    e-mail address from the BSP Application.
    Implementation Details:
    The Print out Output determination is already done in the system. We are using SAP R/3 4.7 (620)
    In the Transaction VF03 in the initial screen there is a menubar "Billing document" and underneath that menu there is a menu item called "Issue". If we click the "Issue" menu item all the output that are already proposed will be visible and we can select the printout Output determination and can issue a printout.
    I had created a FM to call from BSP and that function module will take the Invoice number as input and will call the "VF03" transaction using BDC and will trigger the Sapscript Printout . I see the the sapscript in the spool after I call the Function module .
    But I don't know how I can get the Spool request number for that Function module call from BSP page ????
    I got struck in this approach...
    If I know the Spool number after calling the function module the it's very easy to call the following FM's for sending a e-mail with the Invoice PDF attachment.
    CONVERT_OTFSPOOLJOB_2_PDF
    QCE1_CONVERT
    SO_NEW_DOCUMENT_ATT_SEND_API1
    Please let me know if anyone can help me in this ...
    Please reply ASAP.
    Thanks,
    Greetson

    Check out these weblogs.
    /people/sap.user72/blog/2004/11/10/bsphowto-generate-pdf-output-from-a-bsp
    /people/thomas.jung3/blog/2004/09/08/sending-e-mail-from-abap--version-610-and-higher--bcs-interface
    Regards
    Raja

  • Problem in sending PDF as attachment in E-Mail

    Hi All,
    I have developed a program to convert the spool request as PDF file and sending it to an E-Mail address.
    But when i'm opening the file,  I'm getting an error in Adobe Reader.
    I'm attaching the code here.
    Please give me the suggestions along with example Program.
    Sorry, I could not attach the program here.
    Thanks and regards,
    Jagan Mohan.

    DATA:ig_otf TYPE itcoo OCCURS 0 WITH HEADER LINE,
         ig_pdf_tab LIKE tline OCCURS 0 WITH HEADER LINE.
    DATA : ig_pdf1 TYPE TABLE OF solisti1.
    DATA: g_tab_lines LIKE sy-tabix.
    DATA: ig_objpack LIKE sopcklsti1 OCCURS 2  WITH HEADER LINE,
          ig_objhead LIKE solisti1   OCCURS 1  WITH HEADER LINE,
          ig_objbin LIKE solisti1   OCCURS 10 WITH HEADER LINE,
          ig_reclist LIKE somlreci1  OCCURS 5  WITH HEADER LINE,
          ig_objtxt LIKE solisti1   OCCURS 10 WITH HEADER LINE.
    DATA: wg_doc_chng LIKE sodocchgi1.
    PERFORM convert_pdf.
    PERFORM sendmail.
    FORM convert_pdf .
      REFRESH : ig_otf , ig_pdf_tab.
      ig_otf[] = wg_otf_from_fm-otfdata[].
      CALL FUNCTION 'CONVERT_OTF'
        EXPORTING
          format                = 'PDF'
          max_linewidth         = 132
        IMPORTING
          bin_filesize          = wg_bin_fsize
        TABLES
          otf                   = ig_otf
          lines                 = ig_pdf_tab
        EXCEPTIONS
          err_max_linewidth     = 1
          err_format            = 2
          err_conv_not_possible = 3
          err_bad_otf           = 4
          OTHERS                = 5.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    ENDFORM.                    " convert_pdf
    FORM sendmail .
      REFRESH : ig_pdf1.
      CALL FUNCTION 'SX_TABLE_LINE_WIDTH_CHANGE'
        EXPORTING
          line_width_dst              = '255'
        TABLES
          content_in                  = ig_pdf_tab[]
          content_out                 = ig_pdf1[]
        EXCEPTIONS
          err_line_width_src_too_long = 1
          err_line_width_dst_too_long = 2
          err_conv_failed             = 3
          OTHERS                      = 4.
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      MOVE : 'U'   TO ig_reclist-rec_type,
             '.....'   TO ig_reclist-receiver, " move email id here
             'X'    TO ig_reclist-express,
             'INT' TO ig_reclist-com_type.
      APPEND ig_reclist.
      REFRESH ig_objtxt.
      CONCATENATE 'Payslip of employee -' wg_vbak-vbeln INTO ig_objtxt SEPARATED BY ' '.
      APPEND ig_objtxt.
    Creating the document to be sent
      wg_doc_chng-obj_descr = 'Pay Slip'.
      wg_doc_chng-obj_name  = 'PAYSLIP'.
      wg_doc_chng-obj_langu = sy-langu.
    Get length of objtxt.
      DESCRIBE TABLE ig_objtxt LINES g_tab_lines.
      READ TABLE ig_objtxt INDEX g_tab_lines.
      wg_doc_chng-doc_size = ( g_tab_lines - 1 ) * 255 + STRLEN( ig_objtxt ).
    Creating the entry for the compressed document
      CLEAR ig_objpack-transf_bin.
      ig_objpack-head_start = 1.
      ig_objpack-head_num   = 0.
      ig_objpack-body_start = 1.
      ig_objpack-body_num   = g_tab_lines.
      ig_objpack-doc_type   = 'RAW'.
      APPEND ig_objpack.
      DESCRIBE TABLE ig_pdf1 LINES g_tab_lines.
      g_tab_lines = g_tab_lines + 1.
      ig_objhead-line = 'PAYSLIP'.
      APPEND ig_objhead.
    Creating the entry for the compressed attachment
      ig_objpack-transf_bin = 'X'.
      ig_objpack-head_start = 1.
      ig_objpack-head_num   = 1.
      ig_objpack-body_start = 1.
      ig_objpack-body_num   = g_tab_lines.
      ig_objpack-doc_type   = 'PDF'.
      ig_objpack-obj_name   = 'PAYSLIP'.
      ig_objpack-obj_descr  = 'Pay Slip'.
      ig_objpack-doc_size   = g_tab_lines * 255.
      APPEND ig_objpack.
      CALL FUNCTION 'SO_DOCUMENT_SEND_API1'
        EXPORTING
          document_data                    = wg_doc_chng
         put_in_outbox                    = 'X'
          commit_work                      = 'X'
        TABLES
          packing_list                     = ig_objpack
          object_header                    = ig_objhead
          contents_bin                     = ig_pdf1
          contents_txt                     = ig_objtxt
          receivers                        = ig_reclist
       EXCEPTIONS
         too_many_receivers               = 1
         document_not_sent                = 2
         document_type_not_exist          = 3
         operation_no_authorization       = 4
         parameter_error                  = 5
         x_error                          = 6
         enqueue_error                    = 7
         OTHERS                           = 8 .
      IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.

  • I want to send an email  from my java application

    i want to send an email from my java application

    Then do so...
    You'll probably want to use the JavaMail API (http://java.sun.com/products/javamail) to do that.

  • How to send Secured Mail using Java Mail?

    I want to send mails with "Send Secure" option using Java Mail. Now mails are being sent using Java Mail connecting to smtp host.
    Appreciating your help.
    Thanks.

    There are third party libraries to help with this. Bouncy Castle is very popular.
    See the [JavaMail Third Party Products|http://java.sun.com/products/javamail/Third_Party.html] page.

  • Sending File as attachment using Mail adapter with naming convention

    Dear All,
    I am working on a scenario in which my sender file adapter is sending one file named 'ABC.ok' in one of the folders in application server. I have to send the same file with the same name  to one of the folders at FTP and also to my customer at his email id.
    I have used File Content onversion at the receiver side and has selected adapter specific attributes due to which the required file is getting generated at FTP folder with the same name as that of the source. But how to send the same file using the mail adapter by keeping same name as "ABC.ok". Kindly guide me out in this.
    Regards,
    NJ

    what you need to do:
    1) Select ASMA in Sender and receiver File CC...already done
    2) Using the Dynamic Config UDF get the sender file name in the field Content-Type...for this you need to have a return statement in your UDF
    3) now before pushing this file name to the Content-Type you have to append (concat)the actual type of the file content (xml, txt)
    so your entire Content-Type node will have something like text/plain; name="abc.ok"
    SAP Note has reference on how to do this:
    https://service.sap.com/sap/support/notes/856599
    From the note:
    Q: How can I set the file name of a mail attachment?
    Regards,
    Abhishek.

  • How to send HTML Format Mail using Java Mail in oracle 9i Forms

    Dear All
    could you please tell me how to send HTML Format Mail using Java Mail in oracle 9i Forms and how to implement the java mail ?
    if it is possible, could you please send me the sample code? please very urgent
    Thanks
    P.Sivaraman

    Hello,
    <p>Here is a Form sample.</p>
    Francois

  • Create PDF Application Form Using Java

    Hi
    can Any one help me regarding how to create PDF Application from using java . That application should be doing the action events also.
    Message was edited by:
    helloshiva

    Check these pdf libraries:
    http://www.java-tips.org/java-libraries/pdf-library/

  • Can any one please send me sample programs using java mapping..

    <b>Can any one please send me sample programs using java mapping with input and output?</b>
    please let me know how to get started with java mapping?
    Prerequisites for java mapping ?
    What are the jars need to be deployed for SAX,DOM.  And how to do it in NWDS?
    Use of Execute() and setparameter() ... StreamTransformation?
    Some sample program using java mapping with simple logic(input and output)?

    Hi,
    Did you go thro these blogs?
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-i
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii
    /people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-iii
    Nice blogs to start Java Mapping.
    Go thro this one too.
    /people/stefan.grube/blog/2006/10/23/testing-and-debugging-java-mapping-in-developer-studio
    Regards,
    P.Venkat
    Message was edited by:
            Venkataramanan

  • How to use java mail to send email to hotmail box

    how to use java mail to send email to hotmail box??
    i can send emails to other box(my company's email account) but for hotmail, the program didnt print any err or exception the recepient cant receive the mail.
    thanks

    you ust to download activation.jar and mail.jar and add them to your build path.
    i have used the googlemail smtp server to send mail the code is following:
    public void SendMail()
    Properties props = new Properties();
    props.put("mail.smtp.user", username);
    props.put("mail.smtp.host", host);
    props.put("mail.smtp.port", port);
    props.put("mail.smtp.starttls.enable","true");
    props.put("mail.smtp.auth", "true");
    props.put("mail.smtp.socketFactory.port", port);
    try{
         Authenticator auth = new SMTPAuthenticator(username,password);
    Session session = Session.getInstance(props, auth);
    MimeMessage msg = new MimeMessage(session);
    msg.setText(text);
    msg.setSubject(subject);
    msg.setFrom(new InternetAddress(senderEmail));
    msg.addRecipient(Message.RecipientType.TO, new InternetAddress(receiver));
    Transport.send(msg);
    }catch(Exception ex) {
         System.out.println("Error Sending:");
    System.out.println(ex.getMessage().toString());
    and this the SMTPAuthenticator Class which you will need too.
    class SMTPAuthenticator extends javax.mail.Authenticator {
         private String fUser;
         private String fPassword;
         public SMTPAuthenticator(String user, String password) {
         fUser = user;
         fPassword = password;
         public PasswordAuthentication getPasswordAuthentication() {
         return new PasswordAuthentication(fUser, fPassword);
         }

Maybe you are looking for

  • Sales orders from CRM are not getting blocked with credit check

    Hi All I have configured ECC in such a way that , if cutomer does not have enough creditlimt, then those sales order will get blocked. Our orders will come from CRM, and some times some orders are not getting blocked with credit check even though the

  • Error while initilizing the stock in MB1C T-Code

    Hi gurus,     I am SD Guy. I am getting error when i am posting the stock by using MB1C - T Code. That error is "Number range for Transaction/even type WA in year 2011, does not exist."    I tried by using OBA7-Tcode, but it is not rectifying. Can yo

  • I need help with an assignment

    I have several issues. I am doing a project for a class and I'm stuck. the message doesn't appear in the textbox.  That's the only problem with this code so far. Next thing I haven't been able to figure out is  that I need to add two "do", "do while"

  • Approve quote to be ordered based on workflow activity assigned to the user

    hi, how to approve the quote(cart) to be ordered when user clicks place order based on the workflow activity assigned to the user. regards yesukannan

  • IWeb '08 2.02 slideshow icon

    I recently upgraded to a new iMac, Leopard and the latest version of iWeb. I went through all the hoops of finding my old site (buried because the OS system hides the very necessary ".sites" extension after the words "Domain"! Wasn't that fun for all