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 mail with attachment in apex

C_JMay 15 2016 — edited May 16 2016

hai,

I am trying to send mail with attachment but it is showing error as follows

PLS-00306: wrong number or types of arguments in call to 'ADD_ATTACHMENT' ORA-06550: PL/SQL: Statement ignored

This is the code I wrote

declare 

 

  l_id number; 

 

begin 

 

  l_id := apex_mail.send (  

              p_to    => :P2_TO,  

              p_from  => :P2_FROM,

              p_subj => :P2_SUBJECT,

              p_body      => :P2_BODY);

                    

  APEX_MAIL.ADD_ATTACHMENT (p_mail_id    => l_id, 

                              p_attachment => :P2_ATTACHMENT,

                              p_filename => :P2_FILENAME,

                              p_mime_type => :P2_MIME_TYPE

                              ); 

end;

Please kindly do help me in writing the code. Thanks in advance.

Comments

PMON

It's expecting a BLOB for p_attachment. You can't just pass the page item as bind variable variable because it won't be a blob object.  You need to fetch your blob from your table and pass it into the procedure.

Hope this helps

Bharat G

Can you please let us know the Parameter type of P2_ATTACHMENT

This field should be blob variable. Following is the example:

APEX_MAIL.ADD_ATTACHMENT( p_mail_id    => l_id,

                                  p_attachment => c1.blob_content,

                                  p_filename   => c1.filename,

                                  p_mime_type  => c1.mime_type);


Regards,

Bharat

C_J

r.png

****P2_ATTACHMENT is a file browse field . But when i selected file browse item it showed the source type to be a database column. i have not created any table as it is not required. What I need is i don't want to store these file in any table. i just want send mail with attachment that is stored in desktop . I am new to this , please help me . what to do and how to do. Thanks in advance.


Bharat G

Are you using some tables to store this ?

If you are storing this file in the table, then we can use select statement on that table and we can write PL/SQL script to get the blob content to one temp variable and we can use that in sending emails.

Regards,

Bharat

C_J

how to do that... should I create a table. what all fields should I include

PMON

C_J wrote:

how to do that... should I create a table. what all fields should I include

Check this out...

Oracle APEX Tips: APEX 5 blob column uploads

If you need more info google wwv_flow_files.  Once your blob is uploaded into that table you can fetch it in your plsql block and pass it as the attachment.

Good luck

Bharat G

You can create your own custom table to store files and then you can use it to send email with attachments

Regards,

Bharat

C_J

i created a table and wrote the code like this. I am getting the email in spam and there is no attachment. Please help in solving this....

declare 

 

  l_id number; 

 

begin 

 

  l_id := apex_mail.send (  

              p_to    => :P2_TO,  

              p_from  => :P2_FROM,     

              p_body      => :P2_BODY);

                    

                        

  FOR x IN ( SELECT ATTACHMENT, FILE_NAME, MIME_TYPE FROM SEND_EMAIL WHERE SL_NO = :P2_SL_NO)

              

  LOOP 

 

    APEX_MAIL.ADD_ATTACHMENT (p_mail_id    => l_id, 

                              p_attachment => x.ATTACHMENT,

                              p_filename => x.FILE_NAME,

                              p_mime_type => x.MIME_TYPE

                              ); 

END LOOP; 

 

end;

PMON

Are you sure your file is making it into your table and your loop is running?

C_J

in the table there is no data.... everything is coming in the mail except the attachment file.....

P2_ATTACHMENT here is the file i upload......

Bharat G

In the Item (P2_ATTACHMENT), there is a field Item Source, did you entered that field as blob field in the table ?

Are you creating that Blob using table or creating them manually ?


Regards,

Bharat

C_J

f.png

is this is the one........

Bharat G

Means you created Form using that table which stores files ?

PMON

Your explanation isn't clear.  If you want help you're going to have to provide more details.  The procedure that you're trying to run executes from the database.  Because of that the blob you're trying to attach needs to be on the database server.  So it must either already exist in a table or be uploaded from a form(these are all the example links I've already provided).  If you built an upload form and there is no data in your table, then there's something wrong with your upload form and you need to fix it so that your attachment gets uploaded to your table.  Once this is successful, your mail procedure should attach it as expected.

Hope this clears it up

Bharat G

Try to create one table as following:

CREATE TABLE FILE_UPLOAD_TAB (

BLOB_CONTENT BLOB, MIME_TYPE VARCHAR2(240), FILENAME VARCHAR2(240), CHARSET VARCHAR2(240),

LAST_UPDATED DATE);

And now create one Form Region on the page with the above table and enable only Blob_content column in the form and create it.

And open the Item Which is created using that Blob_Content column and assign

MIME_TYPE, CHARSET, LAST_UPDATED, FILENAME fields to appropriate onces in it and apply changes.

Once this is ready, now try to upload the file and check in the table.

And there after you can write your email process on this table to send emails using that table.

Note: As your table may contains multiple files if you upload more than 1 time. So please use some ID column in the table or delete the old files from table if not necessary. To delete the data from table, write one process before the upload process calls. So that it will delete all the files from table and will load the only latest file and after that our email process will run and send email with that one file as attachment.

This is the entire process we need to follow for files upload UI.

Regards,

Bharat

C_J

thank you...... let me try

C_J

hai,  when i tried this i am get the following error

ORA-01658: unable to create INITIAL extent for segment in tablespace APEX_15160563036964841601

1 - 18
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 13 2016
Added on May 15 2016
18 comments
4,411 views