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

Similar Messages

  • 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

  • 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?

  • Sending binary attachement using UTL_SMTP

    I am attempting to send a .PDF or Word .DOC as an attachment to an email through PL/Sql procedure. Using UTL_FILE to open the file and looping through the file using UTL_FILE.GET_RAW to extract a line then using UTL_SMTP.WRITE_RAW_DATA(conn,UTL_ENCODE.BASE64_ENCODE(<raw data>)) to write the file. I did get an email with the attachment, but when attempting to open the attachment, it cannot because it is corrupt in some way!??!
    The snippet of code is:
    l_file_handle := utl_file.fopen(l_directory_name,l_file_name,'r',32767);
    -- generate the MIME boundary line & header ...
    l_mesg := lcrlf || '--' || l_boundary_text || lcrlf ||
    'Content-Type: '|| p_mime_type|| ';' || lcrlf ||
    'Content-Disposition: attachment; filename="' ||
    l_file_name || '"' || lcrlf ||
    'Content-Transfer-Encoding: ' || p_mime_trnsf_enc || lcrlf || lcrlf;
    utl_smtp.write_data(lconn, l_mesg);
    -- and append the file contents to the end of the message ...
    BEGIN
    LOOP
    IF p_mime_trnsf_enc = '7bit' THEN
    utl_file.get_line(l_file_handle, l_line);
    l_mesg := l_line || lcrlf;
    utl_smtp.write_data(lconn, l_mesg);
    ELSE -- Base-64 encode type
    utl_file.get_raw(l_file_handle, l_line_raw, 100);
    utl_smtp.write_raw_data(lconn, utl_encode.base64_encode(l_line_raw));
    utl_smtp.write_data(lconn,lcrlf);
    END IF;
    END LOOP;
    ... followed by the UTL_FILE exceptions ...
    l_mesg := lcrlf;
    utl_smtp.write_data(lconn,l_mesg);
    utl_file.fclose(l_file_handle);
    Any suggestions???

    The documentation explicitly states:
    "With the UTL_FILE package, your PL/SQL programs can read and write operating system text files"
    See: http://download-east.oracle.com/docs/cd/B10501_01/appdev.920/a96612/u_file.htm#1002119
    Also:
    "UTL_FILE.GET_RAW - This function reads a RAW string value from a file"
    See: http://download-east.oracle.com/docs/cd/B10501_01/appdev.920/a96612/u_file2.htm#1003233
    I agree that this is misleading.
    You can use DBMS_LOB.LOADFROMFILE to read a file into a BLOB. You can then use DBMS_LOB.READ to read from the BLOB to a RAW.
    You can then use the RAW data to build the attachment portion of the email.

  • Sending text Attachment using UTL_SMTP

    Hi,
    I am using UTL_SMTP package for sending a text file thru' a mail.
    Our database is in a unix machine. My file is created in a folder oracle/DEV/CCare/Data which is in the root directory.
    In the URL argument of the procedure,which is a varchar2 type, i am passing the path as 'oracle/DEV/CCare/Data'. Also i have tried passing '/oracle/DEV/CCare/Data' like this. But none of them is working could anybody suggest way of passing the URL.
    The package arguments look like below.
    oks_mail.send_attachment(sender => l_fromemailid,
    recipient_tbl => to_mail_tbl,
    subject => 'Progress report for CCC Feed',
    mail_text => l_mailtext1,
    url => '//10.10.81.3/oracle/DEV/CCare/Data',
    file_name => filename);

    Use
    FILE_ARRAY(1) := file_name;
    RETURN_DESC1 := '10 - E: THERE WAS AN ERROR IN OPENING CONNECTION. ';
    CONN:= UTL_SMTP.OPEN_CONNECTION( L_SMTP_SERVER, L_SMTP_SERVER_PORT ); /** OPEN CONNECTION ON THE SERVER **/
    UTL_SMTP.HELO( CONN, L_SMTP_SERVER ); /** DO THE INITIAL HAND SHAKE **/
    UTL_SMTP.MAIL( CONN, L_SENDER_NAME );
    RETURN_DESC1 := '20 - E: THERE WAS AN ERROR IN CREATING RECEIPIENTS. ';
    UTL_SMTP.RCPT( CONN, '[email protected]');
    UTL_SMTP.OPEN_DATA ( CONN );
    --Send_header('Subject', 'File - ');
    /*** GENERATE THE MIME HEADER ***/
    RETURN_DESC1 := '30 - E: THERE WAS AN ERROR IN GENERATING MIME HEADER. ';
    L_MESG:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' )|| CRLF ||
    'From: ' || L_SENDER_NAME || CRLF ||
    'Subject: ' || file_name || CRLF ||
    'To: ' || L_MSG_TO || CRLF ||
    'Mime-Version: 1.0' || CRLF ||
    'Content-Type: multipart/mixed; boundary="DMW.Boundary.605592468"'|| CRLF ||
    '' || CRLF ||
    'This is a Mime message, which your current mail reader may not' || CRLF ||
    'understand. Parts of the message will appear as text. If the remainder' || CRLF ||
    'appears as random characters in the message body, instead of as' || CRLF ||
    'attachments, then you''ll have to extract these parts and decode them' || CRLF ||
    'manually.' || CRLF ||'' ;/*|| CRLF ||
    '--DMW.Boundary.605592468' || CRLF ||
    'Content-Type: text/plain; name="message.txt"; charset=US-ASCII' || CRLF ||
    'Content-Disposition: inline; filename="message.txt"' || CRLF ||
    'Content-Transfer-Encoding: 7bit' || CRLF ||
    '' || CRLF || CRLF || CRLF || CRLF ;*/
    L_MESG_LEN := LENGTH(L_MESG);
    IF L_MESG_LEN > MAX_SIZE THEN
    MESG_LENGTH_EXCEEDED := TRUE;
    END IF;
    RETURN_DESC1 := '40 - E: THERE WAS AN ERROR IN WRITING MESSAGE TO CONNECTION. ';
    UTL_SMTP.WRITE_DATA ( CONN, L_MESG );
    /*** START ATTACHING THE FILES ***/
    FOR I IN 1..1 LOOP
    EXIT WHEN MESG_LENGTH_EXCEEDED;
    IF FILE_ARRAY(I) IS NOT NULL THEN
    BEGIN
    L_SLASH_POS := INSTR(FILE_ARRAY(I), '/', -1 );
    IF L_SLASH_POS = 0 THEN
    L_SLASH_POS := INSTR(FILE_ARRAY(I), '\', -1 );
    END IF;
    L_DIRECTORY_NAME := SUBSTR(FILE_ARRAY(I), 1, L_SLASH_POS - 1 );
    L_FILE_NAME := SUBSTR(FILE_ARRAY(I), L_SLASH_POS + 1 );
    RETURN_DESC1 := '50 - E: THERE WAS AN ERROR IN OPENING FILE. ';
    L_FILE_HANDLE := UTL_FILE.FOPEN(L_DIRECTORY_NAME, L_FILE_NAME, 'R' );
    L_MESG := CRLF || '--DMW.Boundary.605592468' || CRLF ||
    'Content-Type: application/octet-stream; name="' || L_FILE_NAME || '"' || CRLF ||
    'Content-Disposition: attachment; filename="' || L_FILE_NAME || '"' || CRLF ||
    'Content-Transfer-Encoding: 7bit' || CRLF || CRLF ;
    L_MESG_LEN := L_MESG_LEN + LENGTH(L_MESG);
    UTL_SMTP.WRITE_DATA ( CONN, L_MESG );
    LOOP
    RETURN_DESC1 := '60 - E: THERE WAS AN ERROR IN READING FILE. ';
    UTL_FILE.GET_LINE(L_FILE_HANDLE, L_LINE);
    IF L_MESG_LEN + LENGTH(L_LINE) > MAX_SIZE THEN
    L_MESG := '*** truncated ***' || CRLF;
    UTL_SMTP.WRITE_DATA ( CONN, L_MESG );
    MESG_LENGTH_EXCEEDED := TRUE;
    EXIT;
    END IF;
    L_MESG := L_LINE || CRLF;
    UTL_SMTP.WRITE_DATA ( CONN, L_MESG );
    L_MESG_LEN := L_MESG_LEN + LENGTH(L_MESG);
    END LOOP;
    EXCEPTION
    WHEN NO_DATA_FOUND THEN
    out_errcode:=-500;
    WHEN UTL_FILE.INVALID_PATH THEN
                        RAISE ABORT_PROGRAM;
    WHEN OTHERS THEN
    RAISE ABORT_PROGRAM;
    END;
    L_MESG := CRLF;
    UTL_SMTP.WRITE_DATA ( CONN, L_MESG );
    UTL_FILE.FCLOSE(L_FILE_HANDLE);
    END IF;
    END LOOP;
    RETURN_DESC1 := '70 - E: THERE WAS AN ERROR IN CLOSING MIME BOUNDARY. ';
    L_MESG := CRLF || '--DMW.Boundary.605592468--' || CRLF;
    UTL_SMTP.WRITE_DATA ( CONN, L_MESG );
    UTL_SMTP.CLOSE_DATA( CONN );
    UTL_SMTP.QUIT( CONN );

  • Service command in Preview.app - Send PDF as attachment doesn't work

    I have used the following workflow for month on all my three macs.
    I open up a PDF file in Preview and select "eMail PDF as attachment" from the Edit menu at the top of the screen. This will attach the current viewed PDF file to a new mail message.
    I guess after updating to 10.7.2 somehow it stopped working on MacBook Pro and iMac. My Mac mini is fine. 
    When I do use this command I get two error messages. Service not available. Can't attach PDF to mail. Import failed. Something like that.
    Does anyone know how to fix that? I repaired permissions and did all that kind of stuff.
    Thanks in advance!

    Would it be possible, please, for someone who has/had this issue to send me the com.apple.ServicesMenu.Services.plist files from ~/Library/Containers/com.apple.Preview/Data/Library/Preferences and from ~/Library/Preferences?
    Thank you.

  • Not Able to send pdf as attachment through email

    Hi,
    I am trying to send the generated pdf as attachment throught email and for the same i am referring to this blog
    http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=(J2EE3417100)ID1409662650DB01562818410448928630End?blog=/pub/wlg/8551
    but when i am trying to send the mail using the method given in this blog , i am getting this error
    com.sap.tc.adobe.pdfobject.core.PDFObjectRuntimeException: Processing exception during a "MergeData" operation. Request start time: Fri Dec 11 18:05:24 IST 2009 com.adobe.ProcessingException: PDF is not interactive. Data can only be imported into interactive forms. Exception Stack Trace: com.adobe.ProcessingException: PDF is not interactive
    and at the backend i am getting the error as
    #com.sun.mail.smtp.SMTPSendFailedException: 501 Bad address syntax
    Can any one please help me out with a solution ?? Any suggestions are welcomed
    Thanks a lot in advance

    Hi,
    Thanks for your reply , but i cannot set the enabled property of the form as true as we are not using the licensed version of the live cycle designer . But if i try the example step by step then even by setting the enabled property as false , the pdf is generated and sent through the email and when i am trying to do the same thing in one of my applications its not working . The pdf is generated but as soon as i click on the button send mail the above told error is displayed .
    There needs to be some other explaination for the error

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

  • Converting Sender File as attachment using PayloadSwapBean module

    Hi Expert,
    I have a scenario where I have to pick up a file from PI & send it to another PI server as an attachement using XI Adapter.
    I went through SDN & found several messages describing configuration for attachement for mail & SOAP adapter.
    I attached PayloadSwapBean in my sender File channel & passed keyname as Conent-Disposition & keyValue as attachment however I dont see file being converted as an attachment in SXMB_MONI. It still shows it as main payload.
    Please help me on how to convert a sender file payload into attachement. I would like to keep attachment name same as file name. Let me know how we can do that. I also noticed that on receiver XI adapter (which I would be using to send data to next PI system), you can't attach modules. Let me know if there is some other standard way of achieving this requirement.
    Thanks
    Regards
    Sushil

    Hi Stefan,
    No, I dont see dynamic configuration values in second PI system. I am able to see them in first system.
    Hi Amol,
    Do you see dynamic configuration in second PI? I am still referring ASMA in second PI system as file parameters? Should it be HTTP header? (How are you referring ASMA in second PI). Below is my code which give me null at run time.
    DynamicConfiguration dCon =(DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
    DynamicConfigurationKey dKey = DynamicConfigurationKey.create("http:/"+"/sap.com/xi/XI/System/File","Directory");
    String FileDirectory = dCon.get(dKey);
    return FileDirectory;

  • Random new line issue in email attachment using utl_smtp need your help.

    Hi
    I am getting one problem unable to solve, need your help.
    I am creating one csv attachment in email using utl_smtp.
    but there are random newline in the attachment value so the csv getting corrupted.
    following is the attachment code
    FOR C2 IN CUR_VALIDATION_ERROR
                 LOOP
                   IF CUR_VALIDATION_ERROR%ROWCOUNT = 1 THEN
                     UTL_SMTP.write_data(l_mail_conn,'"LOG DATE","DATA ERROR IDENTIFIER","EMPLOYEE ID","SOURCE SYSTEM","SOURCE FILE ROW","ERROR LEVEL","ERROR MESSAGE"'||CHR(13));
                   END IF; 
                   UTL_SMTP.write_data(l_mail_conn,
                                                     chr(34)||C2.LOG_DT||chr(34)||chr(44)||
                                                     chr(34)||C2.DATA_ERR_ID||chr(34)||chr(44)||
                                                     chr(34)||C2.EMPE_ID||chr(34)||chr(44)||
                                                     chr(34)||C2.SOURCE||chr(34)||chr(44)||
                                                     chr(34)||C2.SOURCE_ROW||chr(34)||chr(44)||
                                                     chr(34)||C2.ERROR_LEVEL||chr(34)||chr(44)||
                                                     chr(34)||C2.ERR_MSG_DSCR||chr(34)||
                                                     CHR(13));
                 END LOOP;

    Thank you hm, but that is not the case, bcz I found newline character inside a sequence number. Its not possible to have newline character inside a sequence number
    "LOG DATE","DATA ERROR IDENTIFIER","EMPLOYEE ID","SOURCE SYSTEM","SOURCE FILE ROW","ERROR LEVEL","ERROR MESSAGE"
    "02-MAY-2012","7893660","123","XYZ","44952","WARNING","[02-MAY-12] - The value in field [PHONE]"
    "02-MAY-2012","7893663","12
    4","XYZ","52382","WARNING","[02-MAY-12] - The value in field [ADDRESS]"

  • Sending PDF forms (created using SFP) as Email Attachment

    Hi,
         I have created bunch of ADOBE forms using SFP. They are not interactive forms. created using ADOBE Live cycle designer.
    I have the Function module and by executing I can view the PDF form in print preview mode. But I have to save this in backend and attach to email.
    I have a program that have to send one of the forms created in SFP as email attachment to outside SAP.
    Please advice how to achieve this.
    Thanks,
    Sanjeev

    Hi ,
    Please find below a code sample for your requirement
    *& Report  ZENVOI_PDF_MAIL
    REPORT  zenvoi_pdf_mail MESSAGE-ID ad.
    TYPE-POOLS : abap .
    DATA : data_for_update TYPE zdemopdf ,
           hexa            TYPE solix_tab.
    DATA : fm_name   TYPE funcname ,
           param     TYPE sfpoutputparams,
           doc_param TYPE sfpdocparams ,
           output    TYPE fpformoutput .
    param-nodialog = abap_true. " suppress printer dialog popup
    param-getpdf = abap_true.
    doc_param-langu = sy-langu.
    doc_param-country = 'FR'.
    doc_param-fillable = abap_true.
    doc_param-dynamic = abap_true.
    CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
      EXPORTING
        i_name     = 'ZDEMO_PDF'
      IMPORTING
        e_funcname = fm_name.
    CALL FUNCTION 'FP_JOB_OPEN'
      CHANGING
        ie_outputparams = param
      EXCEPTIONS
        cancel          = 1
        usage_error     = 2
        system_error    = 3
        internal_error  = 4.
    CHECK sy-subrc EQ 0.
    CALL FUNCTION fm_name
      EXPORTING
        /1bcdwb/docparams  = doc_param
        data_for_update    = data_for_update
      IMPORTING
        /1bcdwb/formoutput = output
      EXCEPTIONS
        usage_error        = 1
        system_error       = 2
        internal_error     = 3.
    CALL FUNCTION 'FP_JOB_CLOSE'
      EXCEPTIONS
        usage_error    = 1
        system_error   = 2
        internal_error = 3
        OTHERS         = 4.
    CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
      EXPORTING
        buffer     = output-pdf "PDF file from function module
      TABLES
        binary_tab = hexa.
    * Envoi du mail
    ** CLASS-DEFINITIONS
    DATA: send_request       TYPE REF TO cl_bcs.
    DATA: document           TYPE REF TO cl_document_bcs.
    *DATA: sender             TYPE REF TO cl_sapuser_bcs.
    data: sender            TYPE REF TO if_sender_bcs.
    DATA: recipient          TYPE REF TO if_recipient_bcs.
    ** INTERNAL TABLES
    DATA: l_mailtext TYPE soli_tab.
    DATA: iaddsmtp   TYPE TABLE OF bapiadsmtp.
    DATA: ireturn    TYPE TABLE OF bapiret2.
    ** VARIABLES
    DATA: mail_line  LIKE LINE OF l_mailtext.
    DATA: bapiadsmtp         TYPE bapiadsmtp.
    DATA: subject    TYPE so_obj_des.
    DATA : att_subject TYPE so_obj_des.
    DATA : w_except TYPE REF TO cx_root .
    CONSTANTS : c_defmail TYPE ad_smtpadr VALUE
                     '[email protected]' .
    FIELD-SYMBOLS : <smtp> TYPE bapiadsmtp.
    *Set subject of the mail
    subject = 'Exemple de PDF interactif'.
    * Set text of the mail
    mail_line = 'Merci de remplir le formulaire et nous le retourner'.
    APPEND mail_line TO l_mailtext .
    att_subject = 'Template du PDF'.
    TRY.
    * Create persistent send request
        send_request = cl_bcs=>create_persistent( ).
    * Get sender object
        sender = cl_sapuser_bcs=>create( sy-uname ).
    *    sender =
    *      cl_cam_address_bcs=>create_internet_address( '[email protected]' ) .
    * Add sender
        CALL METHOD send_request->set_sender
          EXPORTING
            i_sender = sender.
    * Read the E-Mail address for the user
    *    CALL FUNCTION 'BAPI_USER_GET_DETAIL'
    *      EXPORTING
    *        username = sy-uname
    *      TABLES
    *        return   = ireturn
    *        addsmtp  = iaddsmtp.
    *    LOOP AT iaddsmtp ASSIGNING <smtp> WHERE std_no = 'X'.
    *      CLEAR bapiadsmtp.
    *      MOVE <smtp> TO bapiadsmtp.
    *    ENDLOOP.
    *    CASE bapiadsmtp-e_mail.
    *      WHEN space.
            recipient =
         cl_cam_address_bcs=>create_internet_address( c_defmail ).
    *      WHEN OTHERS.
    *        recipient =
    *     cl_cam_address_bcs=>create_internet_address( bapiadsmtp-e_mail ).
    *    ENDCASE.
    * Add recipient with its respective attributes to send request
        CALL METHOD send_request->add_recipient
          EXPORTING
            i_recipient  = recipient
            i_express    = 'X'
            i_copy       = space
            i_blind_copy = space
            i_no_forward = space.
    * Set that you don't need a Return Status E-mail
        CALL METHOD send_request->set_status_attributes
          EXPORTING
            i_requested_status = 'E'
            i_status_mail      = 'E'.
    * set send immediately flag
        send_request->set_send_immediately( 'X' ).
    *Build Document
        document = cl_document_bcs=>create_document(
                            i_type    = 'RAW'
                            i_text    = l_mailtext
                            i_subject = subject ).
    *     add attachment to document
        CALL METHOD document->add_attachment
          EXPORTING
            i_attachment_type    = 'PDF'
            i_attachment_subject = att_subject
            i_att_content_hex    = hexa.
    * Add document to send request
        CALL METHOD send_request->set_document( document ).
    * Send document
        CALL METHOD send_request->send( ).
        COMMIT WORK.
      CATCH cx_send_req_bcs INTO w_except.
      CATCH cx_address_bcs INTO w_except.
      CATCH cx_document_bcs INTO w_except.
    ENDTRY.
    Hope this help you .
    Best regards

  • 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

  • URGENT -java MAil sending pdf as attachment

    I have a small java program that sends the pdf as an attachment without using phisical pdf file.
    but the problem is i am unable to open the pdf that comes as as attachment in mail.
    error while opening pdf : " acrobat cannot open file bcos the file type is not supported or the file is curropted(for example it was sent as email attachment and was not properly decoded)"
    here is the code :
    import java.util.Properties;
    import javax.mail.*;
    import javax.mail.internet.*;
    import javax.activation.*;
    import java.io.*;
    import java.util.*;
    public class Mailer {
    public static void main (String args[]) {
    String host = "abc";
    String from ="[email protected]";
    String to = "[email protected]";
    //String fileAttachment = args[0];
    // Get system properties
    Properties props = System.getProperties();
    // Setup mail server
    props.put("mail.smtp.host", host);
    // Get session
    Session session =
    Session.getInstance(props, null);
    // Define message
    MimeMessage message = new MimeMessage(session);
    message.setFrom( new InternetAddress(from));
    message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
    message.setSubject("Hello JavaMail Attachment subject");
    // create the message part
    MimeBodyPart messageBodyPart = new MimeBodyPart();
    //fill message
    messageBodyPart.setText("Hi hello this is the msg in mail");
    Multipart multipart = new MimeMultipart();
    multipart.addBodyPart(messageBodyPart);
    // Part two is attachment
    messageBodyPart = new MimeBodyPart();
    String data_to_send = "This msg is sent as an attachment with out using physical file";
    String att_type = "application/pdf";
    messageBodyPart.setText(data_to_send);
    messageBodyPart.setHeader("Content-Type", att_type);
    messageBodyPart.setHeader("Content-Transfer-Encoding", "BASE64");
    messageBodyPart.setFileName("attachment.pdf");
    /* ByteArrayOutputStream byteStream=new ByteArrayOutputStream();
    ObjectOutputStream objectStream=new ObjectOutputStream(byteStream);
    objectStream.writeObject(data_to_send);
    messageBodyPart.setDataHandler(new DataHandler( new ByteArrayDataSource( byteStream.toByteArray(), "application/pdf" )));
         messageBodyPart.setFileName("attachment.pdf");
    multipart.addBodyPart(messageBodyPart);
    // Put parts in message
    message.setContent(multipart);
    // Send the message
    Transport.send( message );
    System.out.println("sent msg");
    Thanks
    Smi

    It's "corrupted" because you are sending a text string and not a PDF document.
    And that commented-out code that uses an ObjectOutputStream would have corrupted a PDF document anyway, if you had one.
    I suggest if this problem is urgent then you hire professional programming help to get it done. You are a long way from a solution.

  • 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

  • Sap adobeform sending pdf as attachment with specific name

    Hi Experts,
    Need your help in solving my problem !!
    My requirement is to send adobe form as mail attachment in PDF format, Which I am able to do.
    My Problem is PDF attachment should be generated with specific name.
    For example my scenario (below given screen shot),
    When i click on submit by email button, PDF will be attached to my mail,
    with some random name such as "d4811f8_45171.pdf" Instead it should be generated with
    fixed name such as "new_attach.pdf" or dynamic name using user name such as
    "Vishwa_attachment.pdf".
    Kindly help to achieve my needs.
    Any help will be greatly appreciated and rewarded.
    Thanks in advance,
    Regards,
    Vishwa

    Hi Naveen,
    please read through my query again, I should generate pdf when I click on "submit by email button".
    I am not using any function for conversion it will happen automatically.
    thanks,
    Vishwa

Maybe you are looking for

  • Merging existing pdf documents in Windows 8

    I have just purchased a new HP computer c/w Windows 8, 64 bit. Have loaded my Office 2007 suite and love that I can create PDF files. My question is that I don't know how to merge (add pages to existing pdf documents) my pdf files. Can this be done w

  • How do I view a photo in PHP format on ipad2 via Safari?

    How do I view a photo in PHP format on ipad2 via Safari?

  • Trigger an outbound idoc to sender system after inbound idoc has status 53

    Hi all, We have two different partners (say A and B)which send inbound idoc to ECC of same message type WMMBXY. This updates goods movement. The partner A collects the idocs(WE20 partner profile setting) and partner B trigger's immediately. Now our r

  • How can I release DHCP?

    I have verizon FIOS and in order to switch routers (because my VPN is STILL not working, so I run a test, switch back to linksys, etc) I have to release the DHCP with Verizon FIOS. They retain the MAC address and if don't release, then the other rout

  • Renamed my external hard drive and now cant find photos

    After renaming an external hard drive, what do i do to 'update my folders in lightroom' where to go to find my pics i edited and save to that drive. i originally had it named 'My Book' and renamed it "external 2". i even renamed it back to 'My Book'