Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Send Multiple Attachments

686418Apr 6 2009 — edited Apr 17 2009
I'm not being lazy, I have looked through many of the threads and don't seems to be able to find the answer to this query, if anyone can offer any assistance I'd be very grateful.

I want to send email with multiple attachments and I'm taking advantages of the demo_mail functionality already in place. I can successfully send email with and attachment by passing in the file name from the wwv.flows table after I've uploaded the file. The problem is that I'm not sure how to pass multiple attachments. I imagine I would either be passing multiple file names or combining the blobs?

Code as follows:

procedure email_attachments_asis(
p_sender varchar2, -- sender, example: 'Me '
p_recipients varchar2, -- recipients, example: 'Someone '
p_subject varchar2, -- subject
p_body varchar2, -- body
p_filename varchar2, -- name of pdf file
p_blob blob, -- file(s)
p_mime_type varchar2,
p_number_to_attach number) is


conn utl_smtp.connection;
i number;
len number;
v_eol VARCHAR2(2) := chr(13)||chr(10);


BEGIN

conn := demo_mail.begin_mail(
sender => p_sender,
recipients => p_recipients,
subject => p_subject,
mime_type => demo_mail.MULTIPART_MIME_TYPE);

if p_number_to_attach > 1 then
demo_mail.attach_text(
conn => conn,
data => p_body,
mime_type => p_mime_type);

elsif p_number_to_attach = 1 then

demo_mail.attach_text(
conn => conn,
data => p_body,
mime_type => p_mime_type);

end if;

for counter in 1..p_number_to_attach loop

demo_mail.begin_attachment(
conn => conn,
mime_type => p_mime_type,
inline => TRUE,
filename => p_filename,
transfer_enc => 'base64');

-- split the Base64 encoded attachment into multiple lines
i := 1;
len := DBMS_LOB.getLength(p_blob);

WHILE (i < len) LOOP
IF(i + demo_mail.MAX_BASE64_LINE_WIDTH < len)THEN
UTL_SMTP.Write_Raw_Data (conn
, UTL_ENCODE.Base64_Encode(
DBMS_LOB.Substr(p_blob, demo_mail.MAX_BASE64_LINE_WIDTH, i)));
ELSE
UTL_SMTP.Write_Raw_Data (conn
, UTL_ENCODE.Base64_Encode(
DBMS_LOB.Substr(p_blob, (len - i)+1, i)));
END IF;

UTL_SMTP.Write_Data(conn, UTL_TCP.CRLF);
i := i + demo_mail.MAX_BASE64_LINE_WIDTH;
END LOOP;
end loop;

demo_mail.end_attachment(conn => conn);
demo_mail.end_mail( conn => conn );

END email_attachments_asis;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 15 2009
Added on Apr 6 2009
7 comments
1,654 views