Skip to Main Content

SQL & PL/SQL

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!

Sending UTL_SMTP mail with single jpg attachment issue

PERCY2Jan 11 2011 — edited Sep 27 2013
Hi all,

From last few days i'm struggling to send email with jpg attachment. Recently I manage to send mail with text in the message body but failed to send an attachment with that. I've created one table having one column of LONG RAW data type which stores my images. Now I want to attach this image along with mail body. I've used following code to send text email. I'm using following version of oracle

Oracle Database 10g Release 10.2.0.1.0 - Production
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for 32-bit Windows: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production

Forms version : Forms [32 Bit] Version 10.1.2.0.2 (Production)

My code goes like this ....

DECLARE

v_From VARCHAR2(80) := 'abc@xyz.com';
v_Recipient VARCHAR2(80) := 'abc@xyz.com';
v_Subject VARCHAR2(80) := 'testsubject';
v_Mail_Host VARCHAR2(30) := 'mymailserver';
v_Mail_Conn utl_smtp.Connection;
crlf VARCHAR2(2) := chr(13)||chr(10);

BEGIN

v_Mail_Conn := utl_smtp.Open_Connection(v_Mail_Host, 25);

utl_smtp.Helo(v_Mail_Conn, v_Mail_Host);

utl_smtp.Mail(v_Mail_Conn, v_From);

utl_smtp.Rcpt(v_Mail_Conn, v_Recipient);

utl_smtp.Data(v_Mail_Conn,
*'Date: ' || to_char(sysdate, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf ||*
*'From: ' || v_From || crlf ||*
*'Subject: '|| v_Subject || crlf ||*
*'To: ' || v_Recipient || crlf ||*

*'MIME-Version: 1.0'|| crlf || -- Use MIME mail standard*
*'Content-Type: multipart/mixed;'|| crlf ||*
*' boundary="-----SECBOUND"'|| crlf ||*
crlf ||

*'-------SECBOUND'|| crlf ||*
*'Content-Type: text/plain;'|| crlf ||*
*'Content-Transfer_Encoding: 7bit'|| crlf ||*
crlf ||
*'some message text'|| crlf || -- Message body*
*'more message text'|| crlf ||*
crlf ||

*'-------SECBOUND'|| crlf ||*
-- 'Content-Type: text/plain;'|| crlf ||
*'Content-Type: image/jpg;'|| crlf ||*
-- ' name="excel.csv"'|| crlf ||
*' name="d:\photo\xyz.jpg"'|| crlf ||*
*'Content-Transfer_Encoding: 8bit'|| crlf ||*
*'Content-Disposition: attachment;'|| crlf ||*
-- ' filename="excel.csv"'|| crlf ||
*' filename="xyz.jpg"'|| crlf ||*
crlf ||
*'MY ATTACHMENT '|| crlf || -- Content of attachment*
--'JPG,file,attachement'|| crlf || -- Content of attachment
crlf ||

*'-------SECBOUND--' -- End MIME mail*
*);*

utl_smtp.Quit(v_mail_conn);

EXCEPTION
WHEN utl_smtp.Transient_Error OR utl_smtp.Permanent_Error then
raise_application_error(-20000, 'Unable to send mail: '||sqlerrm);
--message('Unable to send mail');message('Unable to send mail');*
END;

From the above code I've managed to send file with jpg attachment but with
nothing in it. I know i need some logic to build the content of jpg attachment but no idea how to do it... Please guide me how can i attach LONG RAW database image.

Any Help ...

Warm Regards,
Percy
This post has been answered by Saubhik Banerjee on Jan 13 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 25 2013
Added on Jan 11 2011
24 comments
21,916 views