Email with attachement as pdf of submitted form
Hi all,
Can anyone suggest me how to get an email as an acknowledge ment with the submiteed form as an pdf format.?
I want to get an acknowledgement mail after submitting the form through the work space..
and email should contain the submitted form as an attachment in a PDF format
Please assist...
Thank you
You can add an email submit button in your form to achieve this.
Check this - http://help.adobe.com/en_US/livecycle/9.0/designerHelp/index.htm?content=000323.html and http://help.adobe.com/en_US/livecycle/10.0/DesignerHelp/WS107c29ade9134a2c5324ea7712a81c8d a6b-8000.html
Som more pointers which could help
https://groups.google.com/forum/#!topic/livecycle/81OXCQfsNys
http://livecycleapps.wordpress.com/2008/07/28/a-submit-button-that-will-send-an-entire-pdf /
~ Varun
Similar Messages
-
How can i send Email with attacment in pdf/xls with pass word protect
Hi
Can i send Email with attachment in pdf/xls with password protect in oracle apps .Here we want monthly stmt to send the customer with pdf/Xls with
password protect.Is it possible if yes how
ThanksOne option is to convert the report to XML Publisher (which you might have already done as you are asking PDF/XLS), then look into the links below:
http://blogs.oracle.com/xmlpublisher/2007/09/11/
http://blogs.oracle.com/xmlpublisher/2010/02/securing_burst_output_document.html
http://blogs.oracle.com/xmlpublisher/2007/06/merge_and_secure_pdfs.html -
Problem by Sending an Email with attached Adobe Interactive Form (Code)
Thanks. I have written Programm, but it does not work as i want it to do. I will send an Email with attached Adobe Interactive Firm to [email protected]. I tried it with "*lo_recipient = cl_sapuser_bcs=>create( sy-uname )" at the marked(bold, fat) position. It worked but the Email was send to my SAP-Account, but i want to send to [email protected], so I tried this (see at code in bold, fat):
lo_rec TYPE adr6-smtp_addr VALUE '[email protected]'. " Empfänger Receiver
lo_recipient = cl_cam_address_bcs=>create_internet_address( lo_rec ).
But it doens`t send the email.
Can anybody help me please???
Kevin
Here my Code:
Report FP_EXAMPLE_01
Printing of documents using PDF based forms
REPORT z_example_02.
Data declaration
DATA: carr_id TYPE sbook-carrid,
customer TYPE scustom,
bookings TYPE ty_bookings,
connections TYPE ty_connections,
fm_name TYPE rs38l_fnam,
fp_docparams TYPE sfpdocparams,
fp_outputparams TYPE sfpoutputparams,
error_string TYPE string,
l_booking TYPE sbook,
t_sums TYPE TABLE OF sbook,
l_sums LIKE LINE OF t_sums,
fp_formoutput TYPE fpformoutput.
PARAMETER: p_custid TYPE scustom-id DEFAULT 38.
SELECT-OPTIONS: s_carrid FOR carr_id DEFAULT 'AA' TO 'ZZ'.
PARAMETER: p_form TYPE tdsfname DEFAULT 'FP_EXAMPLE_01'.
PARAMETER: language TYPE sfpdocparams-langu DEFAULT 'E'.
PARAMETER: country TYPE sfpdocparams-country DEFAULT 'US'.
Get data from the following tables: scustom(Flight customer)
sbook (Single flight reservation)
spfli (Flight plan)
SELECT SINGLE * FROM scustom INTO customer WHERE id = p_custid.
CHECK sy-subrc = 0.
SELECT * FROM sbook INTO TABLE bookings
WHERE customid = p_custid
AND carrid IN s_carrid
ORDER BY PRIMARY KEY.
SELECT * FROM spfli INTO TABLE connections
FOR ALL ENTRIES IN bookings
WHERE carrid = bookings-carrid
AND connid = bookings-connid
ORDER BY PRIMARY KEY.
Print data:
First get name of the generated function module
CALL FUNCTION 'FP_FUNCTION_MODULE_NAME'
EXPORTING
i_name = p_form
IMPORTING
e_funcname = fm_name.
IF sy-subrc <> 0.
MESSAGE e001(fp_example).
ENDIF.
Set output parameters and open spool job
fp_outputparams-nodialog = 'X'. " suppress printer dialog popup
fp_outputparams-getpdf = 'X'. " launch print preview
CALL FUNCTION 'FP_JOB_OPEN'
CHANGING
ie_outputparams = fp_outputparams
EXCEPTIONS
cancel = 1
usage_error = 2
system_error = 3
internal_error = 4
OTHERS = 5.
Set form language and country (->form locale)
fp_docparams-langu = language.
fp_docparams-country = country.
*fp_docparams-fillable = 'X'.
*fp_docparams-langu = 'E'. "wird jetzt automatisch gesetzt, bzw. kann dynamisch verändert werden
*fp_docparams-country = 'GB'. "wird jetzt automatisch gesetzt, bzw. kann dynamisch verändert werden
currency key dependant summing
LOOP AT bookings INTO l_booking.
l_sums-forcuram = l_booking-forcuram.
l_sums-forcurkey = l_booking-forcurkey.
COLLECT l_sums INTO t_sums.
ENDLOOP.
Now call the generated function module
CALL FUNCTION fm_name
EXPORTING
/1bcdwb/docparams = fp_docparams
customer = customer
bookings = bookings
connections = connections
t_sums = t_sums
IMPORTING
/1bcdwb/formoutput = fp_formoutput
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 3
OTHERS = 4.
IF sy-subrc <> 0.
CALL FUNCTION 'FP_GET_LAST_ADS_ERRSTR'
IMPORTING
e_adserrstr = error_string.
IF NOT error_string IS INITIAL.
we received a detailed error description
WRITE:/ error_string.
EXIT.
ELSE.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
Close spool job
CALL FUNCTION 'FP_JOB_CLOSE'
EXCEPTIONS
usage_error = 1
system_error = 2
internal_error = 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.
*********************Send the form*******************
*********************to the Customer*****************
*********************via Email***********************
*IF i_down = abap_true.
DATA: filename TYPE string,
path TYPE string,
fullpath TYPE string,
default_extension TYPE string VALUE 'PDF'.
Data:
lt_att_content_hex TYPE solix_tab.
*DATA: data_tab TYPE TABLE OF x255.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = fp_formoutput-pdf
TABLES
binary_tab = lt_att_content_hex.
CLASS cl_bcs DEFINITION LOAD.
DATA:
lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
lo_send_request = cl_bcs=>create_persistent( ).
DATA:
lt_message_body TYPE bcsy_text VALUE IS INITIAL.
DATA: lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.
APPEND 'Dear Vendor,' TO lt_message_body.
APPEND ' ' TO lt_message_body.
APPEND 'Please fill the attached form and send it back to us.'
TO lt_message_body.
APPEND ' ' TO lt_message_body.
APPEND 'Thank You,' TO lt_message_body.
lo_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_message_body
i_subject = 'Vendor Payment Form' ).
DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL.
TRY.
lo_document->add_attachment(
EXPORTING
i_attachment_type = 'PDF'
i_attachment_subject = 'Vendor Payment Form'
i_att_content_hex = lt_att_content_hex ).
CATCH cx_document_bcs INTO lx_document_bcs.
ENDTRY.
lo_send_request->set_document( lo_document ).
DATA:
lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,
lo_send TYPE adr6-smtp_addr VALUE '[email protected]'. "Absender SENDER
lo_sender = cl_cam_address_bcs=>create_internet_address( lo_send ).
Set sender
lo_send_request->set_sender(
EXPORTING
i_sender = lo_sender ).
Create recipient
DATA:
lo_recipient type ref to if_recipient_bcs value is initial.
Data:
lo_rec TYPE adr6-smtp_addr VALUE '[email protected]'. " Empfänger Receiver
lo_recipient = cl_cam_address_bcs=>create_internet_address( lo_rec ).
*lo_recipient = cl_sapuser_bcs=>create( sy-uname ).
Set recipient
lo_send_request->add_recipient(
EXPORTING
i_recipient = lo_recipient
i_express = 'X' ).
*lo_send_request->add_recipient(
*EXPORTING
*i_recipient = lo_recipient
*i_express = 'X' ).
Send email
DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL.
lo_send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = lv_sent_to_all ).
COMMIT WORK.
MESSAGE 'The payment form has been emailed to the Vendor' TYPE 'I'.Hi Kevin,
Please try this code to send your mail, i wrote it and works well in many system.
Take care if in your profile you got an e-mail adress define .
Take care also of trnasaction SCOT customizing, are you able to send mail to e-mail adress ?
Let me know if it's works.
Best regards.
<i>**----
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: 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.
*Convert the pdf given by function module into Binary .
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = output-pdf "PDF file from function module
TABLES
binary_tab = hexa.
*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 .
Set the name of the attached document
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 ).
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.
No adress main for user, so send it to the default mail adress
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.</i> -
INBOUND EMAILS with attached interactive form
Hello,
i have send an Email with attached Interactive form to a customer. The customer filled out the form and send it back to the mail-adress that i defined in SCOT! There is a class for rule defined, but i Don`t know if the class is correctly implemented.
But then...where is the email?
i don`t receive it?
Is there anywhere a full code example where i can see how this works???
Is ist better if the cusomer send me an xml or an PDF?
ThanksKevin,
have you checked the eLearning for that topic: https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/5087262b-59ef-2910-abb1-957000b7c3d4
kr, achim -
Send email with attachment PDF
Hi,
i have two environments. One is updated with support package 16 and the other environment isn't updated.
in the environment that is not updated i can send normally email with attachment using smartforms with the function 'SO_NEW_DOCUMENT_ATT_SEND_API1' but now i copied this program to the environment that is updated but the attachment have issue...it don't open.
anybody have some idea to solution?
tks
PatriciaHi,
Check the program 'BCS_EXAMPLE_6' for sending PDF as an attachment. Try sending your PDF using the method specified.
Regards,
Sagar -
Send Email with Attachment in BSP?
Hello,
I have trouble about sending Email in BSP .
I don't know how to <b>Send Email with attachment in BSP</b> . Please give me some advice .
Thank you very much!Here is a sample application..
<b>Layout</b>
<%@page language="abap" %>
<%@extension name="htmlb" prefix="htmlb" %>
<htmlb:content design="design2003" >
<htmlb:page title="Send Mail with Attachment " >
<htmlb:form id = "form1"
encodingType = "multipart/form-data" >
<htmlb:label for = "MAILTO"
text = "Mail to" />
<htmlb:inputField id = "MAILTO"
size = "20"
value = "<%= mail_to %>"
type = "string" />
<htmlb:fileUpload id = "myUpload"
onUpload = "HandleUpload"
upload_text = "Attach"
size = "90" />
</htmlb:form>
</htmlb:page>
</htmlb:content>
<b>Page attributes:</b>
mail_to TYPE ADR6-SMTP_ADDR E-Mail Address
<b> Event handler OnInputprocessing..</b>
DATA: fileUpload TYPE REF TO CL_HTMLB_FILEUPLOAD,
file_content TYPE XSTRING,
file_length TYPE STRING,
file_mime_type TYPE STRING,
file_name TYPE STRING.
fileUpload ?= CL_HTMLB_MANAGER=>GET_DATA(
request = request
id = 'myUpload'
name = 'fileUpload' ).
if fileUpload is not INITIAL.
file_name = fileUpload->file_name.
file_mime_type = fileUpload->file_content_type.
file_length = fileUpload->file_length.
file_content = fileUpload->file_content.
mail_to = request->get_form_field( `MAILTO` ).
* Send mail part..
CLASS cl_bcs DEFINITION LOAD.
DATA:
lo_send_request TYPE REF TO cl_bcs VALUE IS INITIAL.
lo_send_request = cl_bcs=>create_persistent( ).
* Message body and subject
DATA:
lt_message_body TYPE bcsy_text VALUE IS INITIAL,
lt_att_content_hex type solix_tab,
lo_document TYPE REF TO cl_document_bcs VALUE IS INITIAL.
APPEND 'Dear Vendor,' TO lt_message_body.
append ' ' to lt_message_body.
APPEND 'Please find the attached report.'
TO lt_message_body.
append ' ' to lt_message_body.
APPEND 'Thank You,' TO lt_message_body.
lo_document = cl_document_bcs=>create_document(
i_type = 'RAW'
i_text = lt_message_body
i_subject = 'Visit report' ).
data: data_tab type solix_tab,
p_data type XSTRING.
* Pass the data of the document we have uploaded..
p_data = file_content.
call function 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = p_data
TABLES
binary_tab = data_tab.
DATA: lx_document_bcs TYPE REF TO cx_document_bcs VALUE IS INITIAL.
TRY.
lo_document->add_attachment(
EXPORTING
i_attachment_type = 'PDF'
i_attachment_subject = 'Visit Report'
i_att_content_hex = data_tab ).
CATCH cx_document_bcs INTO lx_document_bcs.
ENDTRY.
* Add attachment
* Pass the document to send request
lo_send_request->set_document( lo_document ).
* Create sender
DATA:
lo_sender TYPE REF TO if_sender_bcs VALUE IS INITIAL,
l_send type ADR6-SMTP_ADDR value '[email protected]'.
* Set sender
l_send = mail_to.
lo_sender = cl_cam_address_bcs=>create_internet_address( l_send ).
lo_send_request->set_sender(
EXPORTING
i_sender = lo_sender ).
* Create recipient
DATA:
lo_recipient TYPE REF TO if_recipient_bcs VALUE IS INITIAL.
lo_recipient = cl_sapuser_bcs=>create( sy-uname ).
** Set recipient
lo_send_request->add_recipient(
EXPORTING
i_recipient = lo_recipient
i_express = 'X' ).
lo_send_request->add_recipient(
EXPORTING
i_recipient = lo_recipient
i_express = 'X' ).
* Send email
DATA: lv_sent_to_all(1) TYPE c VALUE IS INITIAL.
lo_send_request->send(
EXPORTING
i_with_error_screen = 'X'
RECEIVING
result = lv_sent_to_all ).
COMMIT WORK.
endif.
Hope this will be helpful.
Raja T -
please help me to find out whether i can reply email and attach some pdf or wordsheets and spreadsheets files from the ipad. for the moment, i can only attach photos which is linked by mail to camera roll.
highly appreciate for your input and enlightmentFirst timer and ten posts promoting this app. This is prohibited by the terms of use of this forum. It's great if if works, but since you seem to work for, or at least promote for the developers of this app, you should note in your post that you are affiliated with the company. The following is an extract of the relevant section of the Apple Support Communities Terms of Use.
No advertising. Do not use the Site to sell or market your products to others and do not post a URL unless it directly answers a user's question. If any portion of your Submission, including any posted URL, results in any accrual of compensation or benefit to you, you must note this in your post by stating, "I may receive some form of compensation, financial or otherwise, from my recommendation or link." As well, the following are not allowed:
A submission created solely to advertise a book, service, software or some other item for sale.
Any reference, including a link, to a commercial item that is not directly related to a relevant technical support question or answer. For example: "This post created by Super Post Creator."
You may sign your Submissions with information about yourself. However, this should not include a link to a website. An example of an acceptable signature:
Justine R.
Author, "Apple Lisa Communities: Tips and Tricks" -
HOW TO SEND A HEBREW EMAIL WITH ATTACHMENT USING DEMO_MAIL
Hello All,
This is Not a question , just attaching something I've implemented and might be interesting for few of us,
This package I'm attaching allows to send Hebrew Language email + attaching files to it.
This package is based on demo_mail package (combined here but you can search at google for more example information if needed).
My Package is supplied as is , for any specific information regarding it , please contact me directly at : [email protected] or POST here.
* Please also note , that this package allow file to be attach via URL (meaning you will have to define a link to this file, if you would like to implement a link to a local file , e.g : c:\temp\myfile , you will have to customize the package your self with database directories option etc ...)
First I will attach an example of how to use it :
==================================
begin
demo_mail_heb.send_html_mail_attach(p_sender => '[email protected]',
p_recipients => '[email protected]',
p_subject => 'שלום וברכה עולם',
p_data => '<hr><b>בוקר טוב</b><hr>',
p_file_name => 'but_choose_file.gif',
p_file_mime_type => 'application/pdf',
p_file_URL => 'http://10.172.246.160:7777/i/but_choose_file.gif');
end;
Second Here is the Package (please note you will have to modify few settings in order to enable it , such as mail server address ..etc)
======================================================================================
CREATE OR REPLACE PACKAGE demo_mail_heb IS
----------------------- Customizable Section -----------------------
-- Customize the SMTP host, port and your domain name below.
smtp_host VARCHAR2(256) := 'mail.oracle.com';
smtp_port PLS_INTEGER := 25;
smtp_domain VARCHAR2(256) := 'oracle.com';
-- Customize the signature that will appear in the email's MIME header.
-- Useful for versioning.
MAILER_ID CONSTANT VARCHAR2(256) := 'Mailer by Oracle UTL_SMTP';
--------------------- End Customizable Section ---------------------
-- A unique string that demarcates boundaries of parts in a multi-part email
-- The string should not appear inside the body of any part of the email.
-- Customize this if needed or generate this randomly dynamically.
BOUNDARY CONSTANT VARCHAR2(256) := '-----7D81B75CCC90D2974F7A1CBD';
FIRST_BOUNDARY CONSTANT VARCHAR2(256) := '--' || BOUNDARY || utl_tcp.CRLF;
LAST_BOUNDARY CONSTANT VARCHAR2(256) := '--' || BOUNDARY || '--' ||
utl_tcp.CRLF;
-- A MIME type that denotes multi-part email (MIME) messages.
MULTIPART_MIME_TYPE CONSTANT VARCHAR2(256) := 'multipart/mixed; boundary="'||
BOUNDARY || '"';
MAX_BASE64_LINE_WIDTH CONSTANT PLS_INTEGER := 76 / 4 * 3;
-- Sent clear Html Email
procedure send_html_mail (p_sender in varchar2 default null,
p_recipients in varchar2 default null,
p_subject in varchar2 default null,
p_data in varchar2 default null,
p_mime_type in varchar2 default 'text/html; charset=windows-1255');
-- Sent Html Email with Attachment
procedure send_html_mail_attach (p_sender in varchar2 default null,
p_recipients in varchar2 default null,
p_subject in varchar2 default null,
p_data in varchar2 default '<b>áå÷ø èåá òåìí - áãé÷ä</b',
p_mime_type in varchar2 default demo_mail_heb.MULTIPART_MIME_TYPE,
p_file_name in varchar2 default 'but_choose_file.gif',
p_file_mime_type in varchar2 default 'application/pdf',
p_file_URL in varchar2 default 'http://10.172.246.160:7777/i/but_choose_file.gif');
-- A simple email API for sending email in plain text in a single call.
-- The format of an email address is one of these:
-- someone@some-domain
-- "Someone at some domain" <someone@some-domain>
-- Someone at some domain <someone@some-domain>
-- The recipients is a list of email addresses separated by
-- either a "," or a ";"
PROCEDURE mail(sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
message IN VARCHAR2);
-- Extended email API to send email in HTML or plain text with no size limit.
-- First, begin the email by begin_mail(). Then, call write_text() repeatedly
-- to send email in ASCII piece-by-piece. Or, call write_mb_text() to send
-- email in non-ASCII or multi-byte character set. End the email with
-- end_mail().
FUNCTION begin_mail(sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
priority IN PLS_INTEGER DEFAULT NULL)
RETURN utl_smtp.connection;
-- Write email body in ASCII
PROCEDURE write_text(conn IN OUT NOCOPY utl_smtp.connection,
message IN VARCHAR2);
-- Write email body in non-ASCII (including multi-byte). The email body
-- will be sent in the database character set.
PROCEDURE write_mb_text(conn IN OUT NOCOPY utl_smtp.connection,
message IN VARCHAR2);
-- Write email body in binary
PROCEDURE write_raw(conn IN OUT NOCOPY utl_smtp.connection,
message IN RAW);
-- APIs to send email with attachments. Attachments are sent by sending
-- emails in "multipart/mixed" MIME format. Specify that MIME format when
-- beginning an email with begin_mail().
-- Send a single text attachment.
PROCEDURE attach_text(conn IN OUT NOCOPY utl_smtp.connection,
data IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
last IN BOOLEAN DEFAULT FALSE);
-- Send a binary attachment. The attachment will be encoded in Base-64
-- encoding format.
PROCEDURE attach_base64(conn IN OUT NOCOPY utl_smtp.connection,
data IN RAW,
mime_type IN VARCHAR2 DEFAULT 'application/octet',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
last IN BOOLEAN DEFAULT FALSE);
-- Send an attachment with no size limit. First, begin the attachment
-- with begin_attachment(). Then, call write_text repeatedly to send
-- the attachment piece-by-piece. If the attachment is text-based but
-- in non-ASCII or multi-byte character set, use write_mb_text() instead.
-- To send binary attachment, the binary content should first be
-- encoded in Base-64 encoding format using the demo package for 8i,
-- or the native one in 9i. End the attachment with end_attachment.
PROCEDURE begin_attachment(conn IN OUT NOCOPY utl_smtp.connection,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
transfer_enc IN VARCHAR2 DEFAULT NULL);
-- End the attachment.
PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection,
last IN BOOLEAN DEFAULT FALSE);
-- End the email.
PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection);
-- Extended email API to send multiple emails in a session for better
-- performance. First, begin an email session with begin_session.
-- Then, begin each email with a session by calling begin_mail_in_session
-- instead of begin_mail. End the email with end_mail_in_session instead
-- of end_mail. End the email session by end_session.
FUNCTION begin_session RETURN utl_smtp.connection;
-- Begin an email in a session.
PROCEDURE begin_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection,
sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
-- mime_type IN VARCHAR2 DEFAULT 'text/plain; charset=windows-1255',
mime_type IN VARCHAR2 DEFAULT 'text/plain',
priority IN PLS_INTEGER DEFAULT NULL);
-- End an email in a session.
PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection);
-- End an email session.
PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection);
END;
CREATE OR REPLACE PACKAGE BODY demo_mail_heb IS
-- Sent clear Html Email
procedure send_html_mail (p_sender in varchar2 default null,
p_recipients in varchar2 default null,
p_subject in varchar2 default null,
p_data in varchar2 default null,
p_mime_type in varchar2 default 'text/html; charset=windows-1255')
Is
conn utl_smtp.connection;
BEGIN
conn := demo_mail_heb.begin_mail(
sender => p_sender,
recipients => p_recipients,
subject => p_subject,
mime_type => p_mime_type);
demo_mail_heb.write_text(
conn => conn,
message => p_data);
demo_mail_heb.end_mail( conn => conn );
END;
-- Sent Html Email with Attachment
procedure send_html_mail_attach (p_sender in varchar2 default null,
p_recipients in varchar2 default null,
p_subject in varchar2 default null,
p_data in varchar2 default '<b>áå÷ø èåá òåìí - áãé÷ä</b',
p_mime_type in varchar2 default demo_mail_heb.MULTIPART_MIME_TYPE,
p_file_name in varchar2 default 'but_choose_file.gif',
p_file_mime_type in varchar2 default 'application/pdf',
p_file_URL in varchar2 default 'http://10.172.246.160:7777/i/but_choose_file.gif')
is
conn utl_smtp.connection;
req utl_http.req;
resp utl_http.resp;
data RAW(200);
begin
conn := demo_mail_heb.begin_mail(
sender => p_sender,
recipients => p_recipients,
subject => p_subject,
mime_type => p_mime_type);
demo_mail_heb.attach_text(
conn => conn,
data => p_data,
mime_type => 'text/html');
demo_mail_heb.begin_attachment(
conn => conn,
mime_type => p_file_mime_type,
inline => TRUE,
filename => p_file_name,
transfer_enc => 'base64');
-- In writing Base-64 encoded text following the MIME format below,
-- the MIME format requires that a long piece of data must be splitted
-- into multiple lines and each line of encoded data cannot exceed
-- 80 characters, including the new-line characters. Also, when
-- splitting the original data into pieces, the length of each chunk
-- of data before encoding must be a multiple of 3, except for the
-- last chunk. The constant demo_mail_heb.MAX_BASE64_LINE_WIDTH
-- (76 / 4 * 3 = 57) is the maximum length (in bytes) of each chunk
-- of data before encoding.
Utl_Http.set_proxy('www-proxy.us.oracle.com', 'oracle.com');
req := utl_http.begin_request(p_file_URL);
resp := utl_http.get_response(req);
BEGIN
LOOP
utl_http.read_raw(resp, data, demo_mail_heb.MAX_BASE64_LINE_WIDTH);
demo_mail_heb.write_raw(
conn => conn,
message => utl_encode.base64_encode(data));
END LOOP;
EXCEPTION
WHEN utl_http.end_of_body THEN
utl_http.end_response(resp);
END;
demo_mail_heb.end_attachment( conn => conn );
demo_mail_heb.end_mail( conn => conn );
end;
-- Return the next email address in the list of email addresses, separated
-- by either a "," or a ";". The format of mailbox may be in one of these:
-- someone@some-domain
-- "Someone at some domain" <someone@some-domain>
-- Someone at some domain <someone@some-domain>
FUNCTION get_address(addr_list IN OUT VARCHAR2) RETURN VARCHAR2 IS
addr VARCHAR2(256);
i pls_integer;
FUNCTION lookup_unquoted_char(str IN VARCHAR2,
chrs IN VARCHAR2) RETURN pls_integer AS
c VARCHAR2(5);
i pls_integer;
len pls_integer;
inside_quote BOOLEAN;
BEGIN
inside_quote := false;
i := 1;
len := length(str);
WHILE (i <= len) LOOP
c := substr(str, i, 1);
IF (inside_quote) THEN
IF (c = '"') THEN
inside_quote := false;
ELSIF (c = '\') THEN
i := i + 1; -- Skip the quote character
END IF;
GOTO next_char;
END IF;
IF (c = '"') THEN
inside_quote := true;
GOTO next_char;
END IF;
IF (instr(chrs, c) >= 1) THEN
RETURN i;
END IF;
<<next_char>>
i := i + 1;
END LOOP;
RETURN 0;
END;
BEGIN
addr_list := ltrim(addr_list);
i := lookup_unquoted_char(addr_list, ',;');
IF (i >= 1) THEN
addr := substr(addr_list, 1, i - 1);
addr_list := substr(addr_list, i + 1);
ELSE
addr := addr_list;
addr_list := '';
END IF;
i := lookup_unquoted_char(addr, '<');
IF (i >= 1) THEN
addr := substr(addr, i + 1);
i := instr(addr, '>');
IF (i >= 1) THEN
addr := substr(addr, 1, i - 1);
END IF;
END IF;
RETURN addr;
END;
-- Write a MIME header
PROCEDURE write_mime_header(conn IN OUT NOCOPY utl_smtp.connection,
name IN VARCHAR2,
value IN VARCHAR2) IS
BEGIN
-- utl_smtp.write_data(conn, name || ': ' || value || utl_tcp.CRLF);
utl_smtp.write_raw_data(conn, UTL_RAW.CAST_TO_RAW(name || ': ' ||value || utl_tcp.CRLF));
END;
-- Mark a message-part boundary. Set <last> to TRUE for the last boundary.
PROCEDURE write_boundary(conn IN OUT NOCOPY utl_smtp.connection,
last IN BOOLEAN DEFAULT FALSE) AS
BEGIN
IF (last) THEN
utl_smtp.write_data(conn, LAST_BOUNDARY);
ELSE
utl_smtp.write_data(conn, FIRST_BOUNDARY);
END IF;
END;
PROCEDURE mail(sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
message IN VARCHAR2) IS
conn utl_smtp.connection;
BEGIN
conn := begin_mail(sender, recipients, subject);
write_text(conn, message);
end_mail(conn);
END;
FUNCTION begin_mail(sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
priority IN PLS_INTEGER DEFAULT NULL)
RETURN utl_smtp.connection IS
conn utl_smtp.connection;
BEGIN
conn := begin_session;
begin_mail_in_session(conn, sender, recipients, subject, mime_type,
priority);
RETURN conn;
END;
PROCEDURE write_text(conn IN OUT NOCOPY utl_smtp.connection,
message IN VARCHAR2) IS
BEGIN
utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(CONVERT(message,'IW8ISO8859P8')));
END;
PROCEDURE write_mb_text(conn IN OUT NOCOPY utl_smtp.connection,
message IN VARCHAR2) IS
BEGIN
utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(message));
END;
PROCEDURE write_raw(conn IN OUT NOCOPY utl_smtp.connection,
message IN RAW) IS
BEGIN
utl_smtp.write_raw_data(conn, message);
END;
PROCEDURE attach_text(conn IN OUT NOCOPY utl_smtp.connection,
data IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
last IN BOOLEAN DEFAULT FALSE) IS
BEGIN
begin_attachment(conn, mime_type, inline, filename);
write_text(conn, data);
end_attachment(conn, last);
END;
PROCEDURE attach_base64(conn IN OUT NOCOPY utl_smtp.connection,
data IN RAW,
mime_type IN VARCHAR2 DEFAULT 'application/octet',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
last IN BOOLEAN DEFAULT FALSE) IS
i PLS_INTEGER;
len PLS_INTEGER;
BEGIN
begin_attachment(conn, mime_type, inline, filename, 'base64');
-- Split the Base64-encoded attachment into multiple lines
i := 1;
len := utl_raw.length(data);
WHILE (i < len) LOOP
IF (i + MAX_BASE64_LINE_WIDTH < len) THEN
utl_smtp.write_raw_data(conn,
utl_encode.base64_encode(utl_raw.substr(data, i,
MAX_BASE64_LINE_WIDTH)));
ELSE
utl_smtp.write_raw_data(conn,
utl_encode.base64_encode(utl_raw.substr(data, i)));
END IF;
utl_smtp.write_data(conn, utl_tcp.CRLF);
i := i + MAX_BASE64_LINE_WIDTH;
END LOOP;
end_attachment(conn, last);
END;
PROCEDURE begin_attachment(conn IN OUT NOCOPY utl_smtp.connection,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
transfer_enc IN VARCHAR2 DEFAULT NULL) IS
BEGIN
write_boundary(conn);
write_mime_header(conn, 'Content-Type', mime_type);
IF (filename IS NOT NULL) THEN
IF (inline) THEN
write_mime_header(conn, 'Content-Disposition',
'inline; filename="'||filename||'"');
ELSE
write_mime_header(conn, 'Content-Disposition',
'attachment; filename="'||filename||'"');
END IF;
END IF;
IF (transfer_enc IS NOT NULL) THEN
write_mime_header(conn, 'Content-Transfer-Encoding', transfer_enc);
END IF;
utl_smtp.write_data(conn, utl_tcp.CRLF);
END;
PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection,
last IN BOOLEAN DEFAULT FALSE) IS
BEGIN
utl_smtp.write_data(conn, utl_tcp.CRLF);
IF (last) THEN
write_boundary(conn, last);
END IF;
END;
PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection) IS
BEGIN
end_mail_in_session(conn);
end_session(conn);
END;
FUNCTION begin_session RETURN utl_smtp.connection IS
conn utl_smtp.connection;
BEGIN
-- open SMTP connection
conn := utl_smtp.open_connection(smtp_host, smtp_port);
utl_smtp.helo(conn, smtp_domain);
RETURN conn;
END;
PROCEDURE begin_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection,
sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
-- mime_type IN VARCHAR2 DEFAULT 'text/plain; charset=windows-1255',
priority IN PLS_INTEGER DEFAULT NULL) IS
my_recipients VARCHAR2(32767) := recipients;
my_sender VARCHAR2(32767) := sender;
BEGIN
-- Specify sender's address (our server allows bogus address
-- as long as it is a full email address ([email protected]).
utl_smtp.mail(conn, get_address(my_sender));
-- Specify recipient(s) of the email.
WHILE (my_recipients IS NOT NULL) LOOP
utl_smtp.rcpt(conn, get_address(my_recipients));
END LOOP;
-- Start body of email
utl_smtp.open_data(conn);
-- Set "From" MIME header
write_mime_header(conn, 'From', sender);
-- Set "To" MIME header
write_mime_header(conn, 'To', recipients);
-- Set "Subject" MIME header
write_mime_header(conn, 'Subject', subject);
-- Set "Content-Type" MIME header
write_mime_header(conn, 'Content-Type', mime_type);
-- Set "X-Mailer" MIME header
write_mime_header(conn, 'X-Mailer', MAILER_ID);
-- Set priority:
-- High Normal Low
-- 1 2 3 4 5
IF (priority IS NOT NULL) THEN
write_mime_header(conn, 'X-Priority', priority);
END IF;
-- Send an empty line to denotes end of MIME headers and
-- beginning of message body.
utl_smtp.write_data(conn, utl_tcp.CRLF);
IF (mime_type LIKE 'multipart/mixed%') THEN
write_text(conn, 'This is a multi-part message in MIME format.' ||
utl_tcp.crlf);
END IF;
END;
PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection) IS
BEGIN
utl_smtp.close_data(conn);
END;
PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection) IS
BEGIN
utl_smtp.quit(conn);
END;
END;Hello All,
Small modification - use this package and not the above
HERE IS A WORKING CODE FOR SENDING HEBREW MESSAGES (INCLUDING SUBJECT IN UTF-8 APPEAR IN ALL EMAIL CLIENTS I HAVE CHECKED) + ATTACHMENTS
Code attached below is supplied as is with no support. anyhow if help is needed , please contact me via [email protected]
============================================================================
CREATE OR REPLACE PACKAGE demo_mail_heb IS
----------------------- Customizable Section -----------------------
-- Customize the SMTP host, port and your domain name below.
smtp_host VARCHAR2(256) := pst_ajax.getParameter('EMAIL_SMTP_HOST');
smtp_port PLS_INTEGER := pst_ajax.getParameter('EMAIL_SMTP_PORT');
smtp_domain VARCHAR2(256) := pst_ajax.getParameter('EMAIL_SMTP_DOMAIN');
-- Customize the signature that will appear in the email's MIME header.
-- Useful for versioning.
MAILER_ID CONSTANT VARCHAR2(256) := 'Mailer by Oracle UTL_SMTP';
--------------------- End Customizable Section ---------------------
-- A unique string that demarcates boundaries of parts in a multi-part email
-- The string should not appear inside the body of any part of the email.
-- Customize this if needed or generate this randomly dynamically.
BOUNDARY CONSTANT VARCHAR2(256) := '-----7D81B75CCC90D2974F7A1CBD';
FIRST_BOUNDARY CONSTANT VARCHAR2(256) := '--' || BOUNDARY || utl_tcp.CRLF;
LAST_BOUNDARY CONSTANT VARCHAR2(256) := '--' || BOUNDARY || '--' ||
utl_tcp.CRLF;
-- A MIME type that denotes multi-part email (MIME) messages.
MULTIPART_MIME_TYPE CONSTANT VARCHAR2(256) := 'multipart/mixed; boundary="'||
BOUNDARY || '"';
MAX_BASE64_LINE_WIDTH CONSTANT PLS_INTEGER := 76 / 4 * 3;
-- Sent clear Html Email
procedure send_html_mail (p_sender in varchar2 default null,
p_recipients in varchar2 default null,
p_subject in varchar2 default null,
p_data in varchar2 default null,
p_mime_type in varchar2 default 'text/html; charset=windows-1255');
-- Sent Html Email with Attachment
procedure send_html_mail_attach (p_sender in varchar2 default null,
p_recipients in varchar2 default null,
p_subject in varchar2 default null,
p_data in varchar2 default '<b>áå÷ø èåá òåìí - áãé÷ä</b',
p_mime_type in varchar2 default 'text/html; charset=windows-1255',
p_file_name in varchar2 default 'but_choose_file.gif',
p_file_mime_type in varchar2 default 'application/pdf',
p_file_URL in varchar2 default 'http://10.172.246.160:7777/i/but_choose_file.gif');
-- A simple email API for sending email in plain text in a single call.
-- The format of an email address is one of these:
-- someone@some-domain
-- "Someone at some domain" <someone@some-domain>
-- Someone at some domain <someone@some-domain>
-- The recipients is a list of email addresses separated by
-- either a "," or a ";"
PROCEDURE mail(sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
message IN VARCHAR2);
-- Extended email API to send email in HTML or plain text with no size limit.
-- First, begin the email by begin_mail(). Then, call write_text() repeatedly
-- to send email in ASCII piece-by-piece. Or, call write_mb_text() to send
-- email in non-ASCII or multi-byte character set. End the email with
-- end_mail().
FUNCTION begin_mail(sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
priority IN PLS_INTEGER DEFAULT NULL)
RETURN utl_smtp.connection;
-- Write email body in ASCII
PROCEDURE write_text(conn IN OUT NOCOPY utl_smtp.connection,
message IN VARCHAR2);
-- Write email body in non-ASCII (including multi-byte). The email body
-- will be sent in the database character set.
PROCEDURE write_mb_text(conn IN OUT NOCOPY utl_smtp.connection,
message IN VARCHAR2);
-- Write email body in binary
PROCEDURE write_raw(conn IN OUT NOCOPY utl_smtp.connection,
message IN RAW);
-- APIs to send email with attachments. Attachments are sent by sending
-- emails in "multipart/mixed" MIME format. Specify that MIME format when
-- beginning an email with begin_mail().
-- Send a single text attachment.
PROCEDURE attach_text(conn IN OUT NOCOPY utl_smtp.connection,
data IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
last IN BOOLEAN DEFAULT FALSE);
-- Send a binary attachment. The attachment will be encoded in Base-64
-- encoding format.
PROCEDURE attach_base64(conn IN OUT NOCOPY utl_smtp.connection,
data IN RAW,
mime_type IN VARCHAR2 DEFAULT 'application/octet',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
last IN BOOLEAN DEFAULT FALSE);
-- Send an attachment with no size limit. First, begin the attachment
-- with begin_attachment(). Then, call write_text repeatedly to send
-- the attachment piece-by-piece. If the attachment is text-based but
-- in non-ASCII or multi-byte character set, use write_mb_text() instead.
-- To send binary attachment, the binary content should first be
-- encoded in Base-64 encoding format using the demo package for 8i,
-- or the native one in 9i. End the attachment with end_attachment.
PROCEDURE begin_attachment(conn IN OUT NOCOPY utl_smtp.connection,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
transfer_enc IN VARCHAR2 DEFAULT NULL);
-- End the attachment.
PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection,
last IN BOOLEAN DEFAULT FALSE);
-- End the email.
PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection);
-- Extended email API to send multiple emails in a session for better
-- performance. First, begin an email session with begin_session.
-- Then, begin each email with a session by calling begin_mail_in_session
-- instead of begin_mail. End the email with end_mail_in_session instead
-- of end_mail. End the email session by end_session.
FUNCTION begin_session RETURN utl_smtp.connection;
-- Handling the Email Subject Line
function mimeheader_encode(
p_str varchar2
, p_charset varchar2 := 'UTF-8') return varchar2;
-- Begin an email in a session.
PROCEDURE begin_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection,
sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
-- mime_type IN VARCHAR2 DEFAULT 'text/plain; charset=windows-1255',
mime_type IN VARCHAR2 DEFAULT 'text/plain',
priority IN PLS_INTEGER DEFAULT NULL);
-- End an email in a session.
PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection);
-- End an email session.
PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection);
END;
CREATE OR REPLACE PACKAGE BODY demo_mail_heb IS
-- Sent clear Html Email
procedure send_html_mail (p_sender in varchar2 default null,
p_recipients in varchar2 default null,
p_subject in varchar2 default null,
p_data in varchar2 default null,
p_mime_type in varchar2 default 'text/html; charset=windows-1255')
Is
conn utl_smtp.connection;
BEGIN
conn := demo_mail_heb.begin_mail(
sender => p_sender,
recipients => p_recipients,
subject => p_subject,
mime_type => 'text/html; charset=UTF-8');--p_mime_type);
demo_mail_heb.write_text(
conn => conn,
message => p_data);
demo_mail_heb.end_mail( conn => conn );
END;
-- Sent Html Email with Attachment
procedure send_html_mail_attach (p_sender in varchar2 default null,
p_recipients in varchar2 default null,
p_subject in varchar2 default null,
p_data in varchar2 default '<b>áå÷ø èåá òåìí - áãé÷ä</b',
p_mime_type in varchar2 default 'text/html; charset=windows-1255',
p_file_name in varchar2 default 'but_choose_file.gif',
p_file_mime_type in varchar2 default 'application/pdf',
p_file_URL in varchar2 default 'http://10.172.246.160:7777/i/but_choose_file.gif')
is
conn utl_smtp.connection;
req utl_http.req;
resp utl_http.resp;
data RAW(200);
v_mime_type varchar2(32767):=demo_mail.MULTIPART_MIME_TYPE;
begin
conn := demo_mail_heb.begin_mail(
sender => p_sender,
recipients => p_recipients,
subject => p_subject,
mime_type => v_mime_type);
demo_mail_heb.attach_text(
conn => conn,
data => p_data,
mime_type => 'text/html');
demo_mail_heb.begin_attachment(
conn => conn,
mime_type => p_file_mime_type,
inline => TRUE,
filename => p_file_name,
transfer_enc => 'base64');
-- In writing Base-64 encoded text following the MIME format below,
-- the MIME format requires that a long piece of data must be splitted
-- into multiple lines and each line of encoded data cannot exceed
-- 80 characters, including the new-line characters. Also, when
-- splitting the original data into pieces, the length of each chunk
-- of data before encoding must be a multiple of 3, except for the
-- last chunk. The constant demo_mail_heb.MAX_BASE64_LINE_WIDTH
-- (76 / 4 * 3 = 57) is the maximum length (in bytes) of each chunk
-- of data before encoding.
req := utl_http.begin_request(p_file_URL);
resp := utl_http.get_response(req);
BEGIN
LOOP
utl_http.read_raw(resp, data, demo_mail_heb.MAX_BASE64_LINE_WIDTH);
demo_mail_heb.write_raw(
conn => conn,
message => utl_encode.base64_encode(data));
END LOOP;
EXCEPTION
WHEN utl_http.end_of_body THEN
utl_http.end_response(resp);
END;
demo_mail_heb.end_attachment( conn => conn );
demo_mail_heb.end_mail( conn => conn );
end;
-- Return the next email address in the list of email addresses, separated
-- by either a "," or a ";". The format of mailbox may be in one of these:
-- someone@some-domain
-- "Someone at some domain" <someone@some-domain>
-- Someone at some domain <someone@some-domain>
FUNCTION get_address(addr_list IN OUT VARCHAR2) RETURN VARCHAR2 IS
addr VARCHAR2(256);
i pls_integer;
FUNCTION lookup_unquoted_char(str IN VARCHAR2,
chrs IN VARCHAR2) RETURN pls_integer AS
c VARCHAR2(5);
i pls_integer;
len pls_integer;
inside_quote BOOLEAN;
BEGIN
inside_quote := false;
i := 1;
len := length(str);
WHILE (i <= len) LOOP
c := substr(str, i, 1);
IF (inside_quote) THEN
IF (c = '"') THEN
inside_quote := false;
ELSIF (c = '\') THEN
i := i + 1; -- Skip the quote character
END IF;
GOTO next_char;
END IF;
IF (c = '"') THEN
inside_quote := true;
GOTO next_char;
END IF;
IF (instr(chrs, c) >= 1) THEN
RETURN i;
END IF;
<<next_char>>
i := i + 1;
END LOOP;
RETURN 0;
END;
BEGIN
addr_list := ltrim(addr_list);
i := lookup_unquoted_char(addr_list, ',;');
IF (i >= 1) THEN
addr := substr(addr_list, 1, i - 1);
addr_list := substr(addr_list, i + 1);
ELSE
addr := addr_list;
addr_list := '';
END IF;
i := lookup_unquoted_char(addr, '<');
IF (i >= 1) THEN
addr := substr(addr, i + 1);
i := instr(addr, '>');
IF (i >= 1) THEN
addr := substr(addr, 1, i - 1);
END IF;
END IF;
RETURN addr;
END;
-- Write a MIME header
PROCEDURE write_mime_header(conn IN OUT NOCOPY utl_smtp.connection,
name IN VARCHAR2,
value IN VARCHAR2) IS
BEGIN
-- utl_smtp.write_data(conn, name || ': ' || value || utl_tcp.CRLF);
utl_smtp.write_raw_data(conn, UTL_RAW.CAST_TO_RAW(name || ': ' ||value || utl_tcp.CRLF));
END;
-- Mark a message-part boundary. Set <last> to TRUE for the last boundary.
PROCEDURE write_boundary(conn IN OUT NOCOPY utl_smtp.connection,
last IN BOOLEAN DEFAULT FALSE) AS
BEGIN
IF (last) THEN
utl_smtp.write_data(conn, LAST_BOUNDARY);
ELSE
utl_smtp.write_data(conn, FIRST_BOUNDARY);
END IF;
END;
PROCEDURE mail(sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
message IN VARCHAR2) IS
conn utl_smtp.connection;
BEGIN
conn := begin_mail(sender, recipients, subject);
write_text(conn, message);
end_mail(conn);
END;
FUNCTION begin_mail(sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
priority IN PLS_INTEGER DEFAULT NULL)
RETURN utl_smtp.connection IS
conn utl_smtp.connection;
BEGIN
conn := begin_session;
begin_mail_in_session(conn, sender, recipients, subject, mime_type,
priority);
RETURN conn;
END;
PROCEDURE write_text(conn IN OUT NOCOPY utl_smtp.connection,
message IN VARCHAR2) IS
BEGIN
utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(CONVERT(message,'IW8ISO8859P8')));
-- utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(message));
END;
PROCEDURE write_mb_text(conn IN OUT NOCOPY utl_smtp.connection,
message IN VARCHAR2) IS
BEGIN
utl_smtp.write_raw_data(conn, utl_raw.cast_to_raw(message));
END;
PROCEDURE write_raw(conn IN OUT NOCOPY utl_smtp.connection,
message IN RAW) IS
BEGIN
utl_smtp.write_raw_data(conn, message);
END;
PROCEDURE attach_text(conn IN OUT NOCOPY utl_smtp.connection,
data IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
last IN BOOLEAN DEFAULT FALSE) IS
BEGIN
begin_attachment(conn, mime_type, inline, filename);
write_text(conn, data);
end_attachment(conn, last);
END;
PROCEDURE attach_base64(conn IN OUT NOCOPY utl_smtp.connection,
data IN RAW,
mime_type IN VARCHAR2 DEFAULT 'application/octet',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
last IN BOOLEAN DEFAULT FALSE) IS
i PLS_INTEGER;
len PLS_INTEGER;
BEGIN
begin_attachment(conn, mime_type, inline, filename, 'base64');
-- Split the Base64-encoded attachment into multiple lines
i := 1;
len := utl_raw.length(data);
WHILE (i < len) LOOP
IF (i + MAX_BASE64_LINE_WIDTH < len) THEN
utl_smtp.write_raw_data(conn,
utl_encode.base64_encode(utl_raw.substr(data, i,
MAX_BASE64_LINE_WIDTH)));
ELSE
utl_smtp.write_raw_data(conn,
utl_encode.base64_encode(utl_raw.substr(data, i)));
END IF;
utl_smtp.write_data(conn, utl_tcp.CRLF);
i := i + MAX_BASE64_LINE_WIDTH;
END LOOP;
end_attachment(conn, last);
END;
PROCEDURE begin_attachment(conn IN OUT NOCOPY utl_smtp.connection,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
transfer_enc IN VARCHAR2 DEFAULT NULL) IS
BEGIN
write_boundary(conn);
write_mime_header(conn, 'Content-Type', mime_type);
IF (filename IS NOT NULL) THEN
IF (inline) THEN
write_mime_header(conn, 'Content-Disposition',
'inline; filename="'||filename||'"');
ELSE
write_mime_header(conn, 'Content-Disposition',
'attachment; filename="'||filename||'"');
END IF;
END IF;
IF (transfer_enc IS NOT NULL) THEN
write_mime_header(conn, 'Content-Transfer-Encoding', transfer_enc);
END IF;
utl_smtp.write_data(conn, utl_tcp.CRLF);
END;
PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection,
last IN BOOLEAN DEFAULT FALSE) IS
BEGIN
utl_smtp.write_data(conn, utl_tcp.CRLF);
IF (last) THEN
write_boundary(conn, last);
END IF;
END;
PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection) IS
BEGIN
end_mail_in_session(conn);
end_session(conn);
END;
FUNCTION begin_session RETURN utl_smtp.connection IS
conn utl_smtp.connection;
BEGIN
-- open SMTP connection
conn := utl_smtp.open_connection(smtp_host, smtp_port);
utl_smtp.helo(conn, smtp_domain);
RETURN conn;
END;
-- Handling the Email Subject Line
function mimeheader_encode(
p_str varchar2
, p_charset varchar2 := 'UTF-8') return varchar2 is
l_str varchar2(2000);
begin
l_str:=utl_raw.cast_to_varchar2(utl_encode.quoted_printable_encode(utl_raw.cast_to_raw(p_str)));
l_str:=replace(l_str,'='||chr(13)||chr(10),''); --unfold the data
l_str:=replace(l_str,'?','=3f'); --quote question marks
l_str:=replace(l_str,' ','=20'); --quote spaces
l_str:='=?'||p_charset||'?Q?'||l_str||'?='; -- add prefix and suffix
return l_str;
end;
PROCEDURE begin_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection,
sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
-- mime_type IN VARCHAR2 DEFAULT 'text/plain; charset=windows-1255',
priority IN PLS_INTEGER DEFAULT NULL) IS
my_recipients VARCHAR2(32767) := recipients;
my_sender VARCHAR2(32767) := sender;
BEGIN
-- Specify sender's address (our server allows bogus address
-- as long as it is a full email address ([email protected]).
utl_smtp.mail(conn, get_address(my_sender));
-- Specify recipient(s) of the email.
WHILE (my_recipients IS NOT NULL) LOOP
utl_smtp.rcpt(conn, get_address(my_recipients));
END LOOP;
-- Start body of email
utl_smtp.open_data(conn);
-- Set "From" MIME header
write_mime_header(conn, 'From', sender);
-- Set "To" MIME header
write_mime_header(conn, 'To', recipients);
-- Set "Content-Type" MIME header
write_mime_header(conn, 'Content-Type', mime_type);
-- write_mime_header(conn, 'Content-Type', 'text/html; charset=UTF-8');
-- Set "Subject" MIME header
-- write_mime_header(conn, 'Subject', subject);
-- write_mime_header(conn, 'Subject', CONVERT(subject,'IW8ISO8859P8'));
write_mime_header(conn, 'Subject',mimeheader_encode(p_str => subject,p_charset => 'UTF-8'));
-- write_mime_header(conn, 'Subject',CONVERT(subject,'IW8MSWIN1255'));
-- Set "X-Mailer" MIME header
write_mime_header(conn, 'X-Mailer', MAILER_ID);
-- Set priority:
-- High Normal Low
-- 1 2 3 4 5
IF (priority IS NOT NULL) THEN
write_mime_header(conn, 'X-Priority', priority);
END IF;
-- Send an empty line to denotes end of MIME headers and
-- beginning of message body.
utl_smtp.write_data(conn, utl_tcp.CRLF);
IF (mime_type LIKE 'multipart/mixed%') THEN
write_text(conn, 'This is a multi-part message in MIME format.' ||
utl_tcp.crlf);
END IF;
END;
PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection) IS
BEGIN
utl_smtp.close_data(conn);
END;
PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection) IS
BEGIN
utl_smtp.quit(conn);
END;
END; -
Can we have more than one attachement to the "Email with Attachment" activity
Guys,
I have a requirement in which the process has n number of approvers in the flow, and each approver can add attachments to the form in the list<document> variable which carries the attahced documents.
At the end of the process i am supposed to send a email with all the attached files to a help desk team.
I know that the Email with attachment activity supports one attachment. is there any posibility or other activity that i can use to send an email with any number of attachments?Hi Ashok
The service you want is called "Send with Map of Attachments". This service is not on the toolbar.
If you drag on the Define Activity step and type "email" in the Find box you will see under Foundation that there are 3 email services.
Choose Send with Map of Attachments.
For help on this service see: http://help.adobe.com/en_US/livecycle/9.0/workbenchHelp/help.htm?content=000570.html
Diana -
How do I create a single PDF Portfolio from an Outlook 2011 email with multiple non-pdf attachments?
Email has 3 attachments--some are not pdf. I'd like all three converted into pdf files along with the email itself, and all appear in the email's pdf portfolio.I would also like an answer to this question.
I am trying to convert an Outlook email to a PDF, then all attachment are appended to the PDF as pages instead of attachments. -
Send email with attachment via XI
Hi,
I need some help regarding sending out email with attchment via XI. My scenario will be I will need to send an email with attachment of Purchase Order (PDF format). I need to do it via XI. Is there any best way for me to configure my SENDER/RECEIVER Mail Adapter in order to send the email with PDF attachment via XI.
Appreciate any valuable thoughts and advice.
Thanks,
ZubairHave you seen these blogs
https://weblogs.sdn.sap.com/pub/wlg/1685 [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken] [original link is broken]
/people/prasad.ulagappan2/blog/2005/06/07/mail-adapter-scenarios-150-sap-exchange-infrastructure
regards
SKM -
When replying to an email with attachment, later when I need to review the attachedment, it can't and just gives a file name <????.pdf> i tried to search my downloads and documents for the file pdf but cant be located.
It seems that attachments are lost when you reply to an email?
Look forward to resolving this problem with LionTry a reset ...
Press and hold the Sleep/Wake button and the Home button together for at least ten seconds, until the Apple logo appears.
If that doesn't help, tap Settings > General > Reset > Reset All Settings
No data is lost due to a reset. -
Hi All
We are successfully able to send email with attachment on sql prompt. The problem is when we are trying to send the attachment through Application Express after submit process its showing the attached file but without its content.
We hav created two such processes. Process one attachs the file as below
declare
file_id number;
begin
delete from dumy_file;
select nvl(max(id),0)+1 into file_id from dumy_file;
insert into dumy_file(id,name,file_obj_id,mime_type,blob_content)
select file_id, filename, id ,mime_type,blob_content
from htmldb_application_files where name = :P2_FILE;
:P2_X := file_id;
end;
And process two send the email with attachment:
declare
file_name varchar2(100);
mim_typ varchar2(50);
begin
select name into file_name from dumy_file where id = :P2_X;
select MIME_TYPE into mim_typ from dumy_file where id = :P2_X;
email_files(from_name => 'Aashu' ,
to_names => :P2_EMAIL,
subject => 'A test from APEX',
message => 'A test message from APEX',
html_message => 'A test message from APEX',
filename1 => file_name,
filetype1 => mim_typ);
end;
Here dumy_file is a custom table.
Any help would be highly appreciated.
Thanks
saurabh[rem Purpose: Sends e-mail (text and/or html, either as a string or from a file)
rem to one or more recipients (including cc and/or bcc recipients), along with
rem up to 3 file attachments (text and/or binary; default is text/plain), using
rem the UTL_SMTP package to send the e-mail, the DBMS_LOB package to read
rem binary file attachments, and the UTL_ENCODE package to convert the binary
rem attachments to BASE64 for character string (non-binary) transmission.
rem BE AWARE THAT A COMMIT MAY BE DONE BY THIS ROUTINE (see HOWEVER... below).
rem
rem The complete parameter list for the email_files procedure is shown below:
rem from_name - name and e-mail address to put in the From field
rem to_names - names and e-mail addresses for the To field (separated by
rem commas or semicolons)
rem subject - text string for Subject field
rem message - text string or text file name for Message, if any
rem html_message - html string or html file name for Message, if any
rem cc_names - names and e-mail addresses for the Cc field, if any
rem (separated by commas or semicolons)
rem bcc_names - names and e-mail addresses for the Bcc field, if any
rem (separated by commas or semicolons)
rem filename1 - first file pathname to attach, if any
rem filetype1 - mime type of first file (defaults to 'text/plain')
rem filename2 - second file pathname to attach, if any
rem filetype2 - mime type of second file (defaults to 'text/plain')
rem filename3 - third file pathname to attach, if any
rem filetype3 - mime type of third file (defaults to 'text/plain')
rem
rem Sample names and e-mail addresses are: srea (attaches @<localhost> or
rem @<mail domain>), [email protected], <[email protected]>, Steve Rea <[email protected]>,
rem and "Steve Rea" <[email protected]> (e-mail addresses must be valid - validity
rem checking is not done on them).
rem
rem A sample call in PL/SQL is shown below, which sends a text and html message,
rem plus a text file and two binary files (note: the slash after "end;" must be
rem the first character on it's line):
rem
rem begin
rem email_files(from_name => 'oracle' ,
rem to_names => '[email protected]',
rem subject => 'A test',
rem message => 'A test message',
rem html_message => '<h2>A <u><i>test</i></u> message</h2>',
rem filename1 => '/tmp/web_ptrbdca.txt',
rem filename2 => '/tmp/password_standards.pdf',
rem filetype2 => 'application/pdf',
rem filename3 => '/tmp/wb703.jpg',
rem filetype3 => 'image/jpeg');
rem end;
rem /
rem
rem If the message or html_message string has a file name in it (starting with
rem a forward slash for unix or starting with '<drive letter>:\' or '\\' for
rem Windows/DOS), the text or html file is copied into the e-mail as the message
rem or html message; otherwise, the message or html_message is copied into the
rem e-mail as-is.
rem
rem Attachment file types (mime types) that I've tested include:
rem text/plain, text/html, image/jpeg, image/gif, application/pdf,
rem application/msword
rem A list of mime types can be seen at:
rem http://www.webmaster-toolkit.com/mime-types.shtml
rem If the mime type does not begin with "text", it is assumed to be a binary
rem file that will be encoded as base64 before transmission.
rem
rem This was derived from several sources, including:
rem Dave Wotton (Cambridge UK) - mail_files.sql at
rem http://home.clara.net/dwotton/dba/oracle_smtp.htm
rem Oracle Technology Network - maildemo.sql (demo_mail) at
rem http://www.oracle.com/technology/sample_code/tech/pl_sql/htdocs/Utl_Smtp_Sample.html
rem Akadia's "Read a file word by word using DBMS_LOB" Tip at
rem http://www.akadia.com/services/read_file_with_dbms_lob.html
rem Tom Kyte of Oracle's AskTom site (http://AskTom.oracle.com) -
rem answer to "File Exists which is not a BFILE" and others.
rem
rem NOTE: The user running this must have "create any directory" and "drop any
rem directory" privileges ("create directory" was introduced in Oracle 9iR2),
rem which must be granted from a system or dba account, such as:
rem grant create any directory to scott;
rem grant drop any directory to scott;
rem then:
rem connect / as sysdba
rem grant select on dba_directories to scott;
rem or, for everyone to have directory privileges:
rem grant create any directory to public;
rem grant drop any directory to public;
rem then:
rem connect / as sysdba
rem grant select on dba_directories to public;
rem Any file in any directory accessible to the user can be attached (not just
rem the directories listed for the utl_file_dir parameter in the init.ora file).
rem HOWEVER, if you are using this to send e-mail's with attached files (or
rem reading the message text or message html from a file) from a trigger or
rem from some other SQL that you can't or don't want to have a commit done,
rem you will first need to create an Oracle directory entry for the directory
rem containing the attached files and grant read access to it to public, such
rem as:
rem create directory CESDIR_COMMON as '/home/common';
rem grant read on directory CESDIR_COMMON to public;
rem
rem You may also want to create a public synonym for this procedure, from the
rem procedure's owner:
rem create or replace public synonym email_files for email_files;
rem grant execute on email_files to public;
rem
rem FYI: I tried using the utl_file package to read binary files:
rem utl_file.get_raw(v_file_handle,data,57);
rem but got "ORA-29284: file read error" on .pdf files, so, I switched to use
rem the dbms_lob package to read binary files:
rem dbms_lob.read(v_bfile_handle,read_bytes,v_pos,data);
rem
rem Author: Stephen Rea <[email protected]>
rem University of Arkansas Cooperative Extension Service
rem Initial release: 12/21/04
rem
rem Updates:
rem 1/31/05 - Fixed for triggers and other SQL that can't have a commit by
rem checking for and using already-defined Oracle directories ("create
rem directory" is a DDL statement that does a commit).
rem 9/23/05 - Put exception handler in to handle the SMTP server being
rem down or unavailable. (Solution from Ed Siegle at Swarthmore.)
rem 7/14/06 - Additional changes to detect and handle Windows/DOS file names
rem (second and third characters ':\' for paths with drive letters, or
rem first and second characters '\\' for UNC paths).
rem 8/25/06 - Some SMTP interfaces may require angle brackets (<>) around the
rem e-mail addresses, so, add them before returning results from get_address.
rem Also, they may not attach the host if relayed through a non-localhost,
rem so, attach the mail domain part (last two components) of the relay host
rem to the address if the mail domain is not specified in the address.
rem
create or replace procedure email_files(from_name varchar2,
to_names varchar2,
subject varchar2,
message varchar2 default null,
html_message varchar2 default null,
cc_names varchar2 default null,
bcc_names varchar2 default null,
filename1 varchar2 default null,
filetype1 varchar2 default 'text/plain',
filename2 varchar2 default null,
filetype2 varchar2 default 'text/plain',
filename3 varchar2 default null,
filetype3 varchar2 default 'text/plain')
is
-- Change the SMTP host name and port number below to your own values,
-- if not localhost on port 25:
smtp_host varchar2(256) := 'localhost';
smtp_port number := 25;
-- Change the boundary string, if needed, which demarcates boundaries of
-- parts in a multi-part email, and should not appear inside the body of
-- any part of the e-mail:
boundary constant varchar2(256) := 'CES.Boundary.DACA587499938898';
recipients varchar2(32767);
directory_path varchar2(256);
file_name varchar2(256);
crlf varchar2(2):= chr(13) || chr(10);
mesg varchar2(32767);
conn UTL_SMTP.CONNECTION;
type varchar2_table is table of varchar2(256) index by binary_integer;
file_array varchar2_table;
type_array varchar2_table;
i binary_integer;
my_code number;
my_errm varchar2(32767);
-- Function to return the next email address in the list of email addresses,
-- separated by either a "," or a ";". From Oracle's demo_mail. The format
-- of mailbox may be in one of these:
-- someone@some-domain
-- "Someone at some domain" <someone@some-domain>
-- Someone at some domain <someone@some-domain>
FUNCTION get_address(addr_list IN OUT VARCHAR2) RETURN VARCHAR2 IS
addr VARCHAR2(256);
i pls_integer;
FUNCTION lookup_unquoted_char(str IN VARCHAR2,
chrs IN VARCHAR2) RETURN pls_integer IS
c VARCHAR2(5);
i pls_integer;
len pls_integer;
inside_quote BOOLEAN;
BEGIN
inside_quote := false;
i := 1;
len := length(str);
WHILE (i <= len) LOOP
c := substr(str, i, 1);
IF (inside_quote) THEN
IF (c = '"') THEN
inside_quote := false;
ELSIF (c = '\') THEN
i := i + 1; -- Skip the quote character
END IF;
GOTO next_char;
END IF;
IF (c = '"') THEN
inside_quote := true;
GOTO next_char;
END IF;
IF (instr(chrs, c) >= 1) THEN
RETURN i;
END IF;
<<next_char>>
i := i + 1;
END LOOP;
RETURN 0;
END;
BEGIN
addr_list := ltrim(addr_list);
i := lookup_unquoted_char(addr_list, ',;');
IF (i >= 1) THEN
addr := substr(addr_list, 1, i - 1);
addr_list := substr(addr_list, i + 1);
ELSE
addr := addr_list;
addr_list := '';
END IF;
i := lookup_unquoted_char(addr, '<');
IF (i >= 1) THEN
addr := substr(addr, i + 1);
i := instr(addr, '>');
IF (i >= 1) THEN
addr := substr(addr, 1, i - 1);
END IF;
END IF;
i := lookup_unquoted_char(addr, '@');
IF (i = 0 and smtp_host != 'localhost') THEN
i := instr(smtp_host, '.', -1, 2);
addr := addr || '@' || substr(smtp_host, i + 1);
END IF;
addr := '<' || addr || '>';
RETURN addr;
END;
-- Procedure to split a file pathname into its directory path and file name
-- components.
PROCEDURE split_path_name(file_path IN VARCHAR2, directory_path OUT VARCHAR2,
file_name OUT VARCHAR2) IS
pos number;
begin
-- Separate the filename from the directory name
pos := instr(file_path,'/',-1);
if pos = 0 then
pos := instr(file_path,'\',-1);
end if;
if pos = 0 then
directory_path := null;
else
directory_path := substr(file_path,1,pos - 1);
end if;
file_name := substr(file_path,pos + 1);
end;
-- Procedure to append a file's contents to the e-mail
PROCEDURE append_file(directory_path IN VARCHAR2, file_name IN VARCHAR2,
file_type IN VARCHAR2, conn IN OUT UTL_SMTP.CONNECTION) IS
generated_name varchar2(30) := 'CESDIR' || to_char(sysdate,'HH24MISS');
directory_name varchar2(30);
file_handle utl_file.file_type;
bfile_handle bfile;
bfile_len number;
pos number;
read_bytes number;
line varchar2(1000);
data raw(200);
my_code number;
my_errm varchar2(32767);
begin
begin
-- Grant access to the directory, unless already defined, and open
-- the file (as a bfile for a binary file, otherwise as a text file).
begin
line := directory_path;
select dd.directory_name into directory_name from dba_directories dd
where dd.directory_path = line and rownum = 1;
exception
when no_data_found then
directory_name := generated_name;
end;
if directory_name = generated_name then
execute immediate 'create or replace directory ' || directory_name ||
' as ''' || directory_path || '''';
execute immediate 'grant read on directory ' || directory_name ||
' to public';
end if;
if substr(file_type,1,4) != 'text' then
bfile_handle := bfilename(directory_name,file_name);
bfile_len := dbms_lob.getlength(bfile_handle);
pos := 1;
dbms_lob.open(bfile_handle,dbms_lob.lob_readonly);
else
file_handle := utl_file.fopen(directory_name,file_name,'r');
end if;
-- Append the file contents to the end of the message
loop
-- If it is a binary file, process it 57 bytes at a time,
-- reading them in with a LOB read, encoding them in BASE64,
-- and writing out the encoded binary string as raw data
if substr(file_type,1,4) != 'text' then
if pos + 57 - 1 > bfile_len then
read_bytes := bfile_len - pos + 1;
else
read_bytes := 57;
end if;
dbms_lob.read(bfile_handle,read_bytes,pos,data);
utl_smtp.write_raw_data(conn,utl_encode.base64_encode(data));
pos := pos + 57;
if pos > bfile_len then
exit;
end if;
-- If it is a text file, get the next line of text, append a
-- carriage return / line feed to it, and write it out
else
utl_file.get_line(file_handle,line);
utl_smtp.write_data(conn,line || crlf);
end if;
end loop;
-- Output any errors, except at end when no more data is found
exception
when no_data_found then
null;
when others then
my_code := SQLCODE;
my_errm := SQLERRM;
dbms_output.put_line('Error code ' || my_code || ': ' ||
my_errm);
end;
-- Close the file (binary or text)
if substr(file_type,1,4) != 'text' then
dbms_lob.close(bfile_handle);
else
utl_file.fclose(file_handle);
end if;
if directory_name = generated_name then
execute immediate 'drop directory ' || directory_name;
end if;
end;
begin
-- Load the three filenames and file (mime) types into an array for
-- easier handling later
file_array(1) := filename1;
file_array(2) := filename2;
file_array(3) := filename3;
type_array(1) := filetype1;
type_array(2) := filetype2;
type_array(3) := filetype3;
-- Open the SMTP connection and set the From and To e-mail addresses
conn := utl_smtp.open_connection(smtp_host,smtp_port);
utl_smtp.helo(conn,smtp_host);
recipients := from_name;
utl_smtp.mail(conn,get_address(recipients));
recipients := to_names;
while recipients is not null loop
utl_smtp.rcpt(conn,get_address(recipients));
end loop;
recipients := cc_names;
while recipients is not null loop
utl_smtp.rcpt(conn,get_address(recipients));
end loop;
recipients := bcc_names;
while recipients is not null loop
utl_smtp.rcpt(conn,get_address(recipients));
end loop;
utl_smtp.open_data(conn);
-- Build the start of the mail message
mesg := 'Date: ' || TO_CHAR(SYSDATE,'dd Mon yy hh24:mi:ss') || crlf ||
'From: ' || from_name || crlf ||
'Subject: ' || subject || crlf ||
'To: ' || to_names || crlf;
if cc_names is not null then
mesg := mesg || 'Cc: ' || cc_names || crlf;
end if;
if bcc_names is not null then
mesg := mesg || 'Bcc: ' || bcc_names || crlf;
end if;
mesg := mesg || 'Mime-Version: 1.0' || crlf ||
'Content-Type: multipart/mixed; boundary="' || boundary || '"' ||
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;
utl_smtp.write_data(conn,mesg);
-- Write the text message or message file, if any
if message is not null then
mesg := '--' || boundary || 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;
utl_smtp.write_data(conn,mesg);
if instr(message,'/') = 1 or instr(message,':\') = 2 or
instr(message,'\\') = 1 then
split_path_name(message,directory_path,file_name);
append_file(directory_path,file_name,'text',conn);
utl_smtp.write_data(conn,crlf);
else
utl_smtp.write_data(conn,message || crlf);
end if;
end if;
-- Write the HTML message or message file, if any
if html_message is not null then
mesg := '--' || boundary || crlf ||
'Content-Type: text/html; name="message.html"; charset=US-ASCII' ||
crlf ||
'Content-Disposition: inline; filename="message.html"' || crlf ||
'Content-Transfer-Encoding: 7bit' || crlf || crlf;
utl_smtp.write_data(conn,mesg);
if instr(html_message,'/') = 1 or instr(html_message,':\') = 2 or
instr(html_message,'\\') = 1 then
split_path_name(html_message,directory_path,file_name);
append_file(directory_path,file_name,'text',conn);
utl_smtp.write_data(conn,crlf);
else
utl_smtp.write_data(conn,html_message || crlf);
end if;
end if;
-- Append the files
for i in 1..3 loop
-- If the filename has been supplied ...
if file_array(i) is not null then
split_path_name(file_array(i),directory_path,file_name);
-- Generate the MIME boundary line according to the file (mime) type
-- specified.
mesg := crlf || '--' || boundary || crlf;
if substr(type_array(i),1,4) != 'text' then
mesg := mesg || 'Content-Type: ' || type_array(i) ||
'; name="' || file_name || '"' || crlf ||
'Content-Disposition: attachment; filename="' ||
file_name || '"' || crlf ||
'Content-Transfer-Encoding: base64' || crlf || crlf ;
else
mesg := mesg || 'Content-Type: application/octet-stream; name="' ||
file_name || '"' || crlf ||
'Content-Disposition: attachment; filename="' ||
file_name || '"' || crlf ||
'Content-Transfer-Encoding: 7bit' || crlf || crlf ;
end if;
utl_smtp.write_data(conn,mesg);
-- Append the file contents to the end of the message
append_file(directory_path,file_name,type_array(i),conn);
utl_smtp.write_data(conn,crlf);
end if;
end loop;
-- Append the final boundary line
mesg := crlf || '--' || boundary || '--' || crlf;
utl_smtp.write_data(conn,mesg);
-- Close the SMTP connection
utl_smtp.close_data(conn);
utl_smtp.quit(conn);
exception
when utl_smtp.transient_error or utl_smtp.permanent_error then
my_code := SQLCODE;
my_errm := SQLERRM;
begin
utl_smtp.quit(conn);
exception
when utl_smtp.transient_error or utl_smtp.permanent_error then
null;
end;
raise_application_error(-20000,
'Failed to send mail - SMTP server down or unavailable: Error code ' ||
my_code || ': ' || my_errm);
when others then
my_code := SQLCODE;
my_errm := SQLERRM;
raise_application_error(-20000,
'Failed to send mail: Error code ' || my_code || ': ' || my_errm);
end;
Above is the code as required by you.In my original mail I have explained that how I'm calling this procedure.
Thanks
Saurabh -
BPEL send email with attachment
Hi guys,,
Now i want to send email with attachment from the bpel console. In bpel console, if i want to use, "browse" button, how can i create this button in my xsd file?Hello,
Well I'm using the BPEL build in decoder. It works for txt file but how about PDF? Will it be the same?
it give me this message in the email process.
XML Parsing Error: reference to invalid character number
p/s: it working to txt but not pdf.
below is the script
<bpelx:exec name="decoder" language="java" version="1.5">
<![CDATA[String inputString = new String();
inputString =(String)getVariableData("attachmentContentVar");
try {
String decoded = Base64Decoder.decode(inputString);
setVariableData("decoded",decoded);
catch(Exception e)
e.printStackTrace();
}]]>
</bpelx:exec>
<copy>
<from variable="retriveAttachment_retriveAttachmentSelect_TASKID_OutputVariable"
part="WfattachmentCollection"
query="/ns3:WfattachmentCollection/ns3:Wfattachment/ns3:encoding"/>
<to variable="varNotificationReq" part="EmailPayload"
query="/EmailPayload/ns1:Content/ns1:ContentBody/ns1:MultiPart/ns1:BodyPart[2]/ns1:MimeType"/>
</copy>
<copy>
<from variable="retriveAttachment_retriveAttachmentSelect_TASKID_OutputVariable"
part="WfattachmentCollection"
query="/ns3:WfattachmentCollection/ns3:Wfattachment/ns3:name"/>
<to variable="varNotificationReq" part="EmailPayload"
query="/EmailPayload/ns1:Content/ns1:ContentBody/ns1:MultiPart/ns1:BodyPart[2]/ns1:BodyPartName"/>
</copy>
<copy>
<from expression="bpws:getVariableData('decoded')"/>
<to variable="varNotificationReq" part="EmailPayload"
query="/EmailPayload/ns1:Content/ns1:ContentBody/ns1:MultiPart/ns1:BodyPart[2]/ns1:ContentBody"/>
</copy>
</assign>
Edited by: kpchong on Oct 20, 2009 12:00 AM -
Send Email with attachment further .
Hello All,
Thank Raja Thangamani for giving me an answer about <b>Send Email with attachment</b> . But now I have a new question that when I sene Email with attachment beyond 500M , this funtion is not applied .
Pls give me some advice! Thanks very much!Look at this link & thread..
http://www.thespot4sap.com/Articles/SAP_Mail_UNIX_Example_ABAP.asp
Send PDF Attachment to SAP Mail Inbox.
Hope this will solve your problem.
Raja T
Message was edited by:
Raja Thangamani
Maybe you are looking for
-
Hello i have an application deployed on weblogic 11. after 30mins the application session times out. 1.how can increase this time. 2. can this be done in weblogic since on the application side there is no configuration for the time out. please assist
-
How do i remove old messages from my iphone 5s to free up space?
delete old messages
-
Hi I am having problem when trying to open files after having exported from multiple artboards from Adobe Illustrator CS5. I received the following message when trying to open the PNG in Photoshop and Fireworks: 'Could not complete your request becau
-
I have AW 6 and am obviously new at it. How do I create it with all the accents showing automatically?
-
Making a print calendar from iPhoto
I am using iphoto to make a print calendar. I chose the "picture calendar" option. After inserting my photos, I noticed that the font size of the month on each page (e.g., January 2015) had become tiny (like 6 pt). How do I adjust that back to the