Problem solve Get help with specific problems with your technologies, process and projects.

Procedure for sending attachments via utl_smtp

Could you please provide a PL/SQL procedure to send an e-mail with an attachment from Oracle? I know utl_smtp is used, and I had to send e-mails from it, but now I have to send an attachment with it. I have Oracle9i database.

Prior to Oracle 9i you could not send an attachment using UTL_SMTP. You had to have JAVA VM and use Java Mail to...

perform the task.

Starting with Oracle 9i UTL_SMTP has introduced some primitives that let you perform the desired task. The demo below is the courtesy of Oracle Technology Network and I have provided the example for your review.

UTL_SMTP is very low level and a simple task of sending a plain text may require multiple calls. Keep that in mind. The maildemo package presents a higher level API that makes the task a bit easier for application programmers.

You can send an e-mail with attachments by:

  1. Addressing it and setting the message MIME-Type
  2. Ensuring the message parts are defined modularly
  3. Adding character attachment(s) with defined MIME type
  4. Adding binary attachment(s) with defined MIME type and encoding scheme
  5. Stating whether each attachment is to be inline or not

Click here to view the procedure.

Dig Deeper on Using Oracle PL-SQL