Email is sent correctly, but attachment appears in the body

Hi,
I am trying to send emails with attachments in pl/sql.
I heard it can be done.
I tried it, the code runs wiithout erros.
But i cannot see the actual attachment.
The content of the attachment appears in the body of the email.
In the email i see this:
This is an automated email. Please do not reply!
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="-----AABCDEFBBCCC0123456789DE"
This is a multi-part message in MIME format.
-------AABCDEFBBCCC0123456789DE
Content-Type: text/html;US-ASCII
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="your_file_name.csv"
SYS,ICOL$,TABLE,2009-06-19 15:35:34
SYS,I_USER1,INDEX,2009-06-19 15:35:34
SYS,CON$,TABLE,2009-06-19 15:35:34
SYS,UNDO$,TABLE,2009-06-19 15:35:34
SYS,C_COBJ#,CLUSTER,2009-06-19 15:35:34
SYS,I_OBJ#,INDEX,2009-06-19 15:35:34
SYS,PROXY_ROLE_DATA$,TABLE,2009-06-19 15:35:34
SYS,I_IND1,INDEX,2009-06-19 15:35:34
SYS,I_CDEF2,INDEX,2009-06-19 15:35:34
SYS,I_PROXY_ROLE_DATA$_1,INDEX,2009-06-19 15:35:34
SYS,FILE$,TABLE,2009-06-19 15:35:34
SYS,UET$,TABLE,2009-06-19 15:35:34
SYS,I_FILE#_BLOCK#,INDEX,2009-06-19 15:35:34
SYS,I_FILE1,INDEX,2009-06-19 15:35:34
SYS,I_CON1,INDEX,2009-06-19 15:35:34
SYS,I_OBJ3,INDEX,2009-06-19 15:35:34
SYS,I_TS#,INDEX,2009-06-19 15:35:34
SYS,I_CDEF4,INDEX,2009-06-19 15:35:34
SYS,IND$,TABLE,2009-06-19 15:35:34
-------AABCDEFBBCCC0123456789DE--
The part between the boundry
(-------AABCDEFBBCCC0123456789DE--) should come as an attachment.
Code for attachment:
PROCEDURE R040_attach
IS
v_clob clob := empty_clob();
c_mime_boundary VARCHAR2(256) := '-----AABCDEFBBCCC0123456789DE';
v_len INTEGER;
v_index INTEGER;
BEGIN
FOR x IN (SELECT *
FROM all_objects
WHERE ROWNUM < 20)
LOOP
v_clob :=
v_clob
|| x.owner
|| ','
|| x.object_name
|| ','
|| x.object_type
|| ','
|| TO_CHAR(x.created, 'yyyy-mm-dd hh24:mi:ss')
|| UTL_TCP.crlf;
END LOOP;
UTL_SMTP.write_data(c, 'MIME-Version: 1.0' || UTL_TCP.crlf);
UTL_SMTP.write_data(
c,
'Content-Type: multipart/mixed; boundary="' || c_mime_boundary || '"' || UTL_TCP.crlf
UTL_SMTP.write_data(c, UTL_TCP.crlf);
UTL_SMTP.write_data(
c,
'This is a multi-part message in MIME format.' || UTL_TCP.crlf
UTL_SMTP.write_data(c, '--' || c_mime_boundary || UTL_TCP.crlf);
--UTL_SMTP.write_data(c, 'Content-Type: text/html;US-ASCII' || UTL_TCP.crlf);
--Content-Type: image/jpeg
UTL_SMTP.write_data(
c,
'Content-Type: text/html;US-ASCII'
|| UTL_TCP.crlf
|| 'Content-Transfer-Encoding: base64'
|| UTL_TCP.crlf
-- Set up attachment header
UTL_SMTP.write_data(
c,
'Content-Disposition: attachment; filename="'
|| 'your_file_name.csv'
|| '"'
|| UTL_TCP.crlf
UTL_SMTP.write_data(c, UTL_TCP.crlf);
-- Write attachment contents
v_len := DBMS_LOB.getlength(v_clob);
v_index := 1;
WHILE v_index <= v_len
LOOP
UTL_SMTP.write_data(c, DBMS_LOB.SUBSTR(v_clob, 32000, v_index));
v_index := v_index + 32000;
END LOOP;
-- End attachment
UTL_SMTP.write_data(c, UTL_TCP.crlf);
UTL_SMTP.write_data(c, '--' || c_mime_boundary || '--' || UTL_TCP.crlf);
EXCEPTION
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR( -20110, 'Dwx0110 - R030 - ' || SQLERRM );
END R040_attach;
Any help would be appreciated.
Thank you.

This is the forum for Oracle's SQL Developer tool, not for general SQL and PL/SQL questions.
Questions like this will get a better response in the PL/SQL forum.
Here is some code I have used to send emails with attachments.
  utl_smtp.open_data(conn);
  utl_smtp.write_data(conn,'Subject:'||subject);
   utl_smtp.write_data( conn, utl_tcp.crlf );
  utl_smtp.write_data( conn, 'Content-Disposition: attachment; filename="attachment"' || utl_tcp.crlf);
    utl_smtp.write_data( conn, 'Content-Transfer-Encoding: base64' || utl_tcp.crlf );
    utl_smtp.write_data( conn, utl_tcp.crlf );
    v_length := dbms_lob.getlength(attachment);
    <<while_loop>>
    while v_offset < v_length loop
      dbms_lob.read( attachment, v_buffer_size, v_offset, v_raw );
      utl_smtp.write_raw_data( conn, utl_encode.base64_encode(v_raw) );
      utl_smtp.write_data( conn, utl_tcp.crlf );
      v_offset := v_offset + v_buffer_size;
    end loop while_loop;
    utl_smtp.write_data( conn, utl_tcp.crlf );
  utl_smtp.write_data(conn,utl_tcp.crlf||utl_tcp.crlf);
  utl_smtp.write_data(conn,content);
  utl_smtp.write_data(conn,utl_tcp.crlf||utl_tcp.crlf);
  utl_smtp.close_data(conn);
content is a varchar holding the body of the email.
attachment is a blob holding the attachment.
Edited by: Jim Smith on Nov 2, 2012 9:24 AM

Similar Messages

  • Email sent...but attachment appears in body

    Hi,
    I am trying to send emails with attachments in pl/sql.
    I heard it can be done.
    I tried it, the code runs wiithout erros.
    But i cannot see the actual attachment.
    The content of the attachment appears in the body of the email.
    In the email i see this:
    This is an automated email. Please do not reply!
    MIME-Version: 1.0
    Content-Type: multipart/mixed; boundary="-----AABCDEFBBCCC0123456789DE"
    This is a multi-part message in MIME format.
    -------AABCDEFBBCCC0123456789DE
    Content-Type: text/html;US-ASCII
    Content-Transfer-Encoding: base64
    Content-Disposition: attachment; filename="your_file_name.csv"
    SYS,ICOL$,TABLE,2009-06-19 15:35:34
    SYS,I_USER1,INDEX,2009-06-19 15:35:34
    SYS,CON$,TABLE,2009-06-19 15:35:34
    SYS,UNDO$,TABLE,2009-06-19 15:35:34
    SYS,C_COBJ#,CLUSTER,2009-06-19 15:35:34
    SYS,I_OBJ#,INDEX,2009-06-19 15:35:34
    SYS,PROXY_ROLE_DATA$,TABLE,2009-06-19 15:35:34
    SYS,I_IND1,INDEX,2009-06-19 15:35:34
    SYS,I_CDEF2,INDEX,2009-06-19 15:35:34
    SYS,I_PROXY_ROLE_DATA$_1,INDEX,2009-06-19 15:35:34
    SYS,FILE$,TABLE,2009-06-19 15:35:34
    SYS,UET$,TABLE,2009-06-19 15:35:34
    SYS,I_FILE#_BLOCK#,INDEX,2009-06-19 15:35:34
    SYS,I_FILE1,INDEX,2009-06-19 15:35:34
    SYS,I_CON1,INDEX,2009-06-19 15:35:34
    SYS,I_OBJ3,INDEX,2009-06-19 15:35:34
    SYS,I_TS#,INDEX,2009-06-19 15:35:34
    SYS,I_CDEF4,INDEX,2009-06-19 15:35:34
    SYS,IND$,TABLE,2009-06-19 15:35:34
    -------AABCDEFBBCCC0123456789DE--
    The part between the boundry
    (-------AABCDEFBBCCC0123456789DE--) should come as an attachment.
    Code for attachment:
    PROCEDURE R040_attach
    IS
    v_clob clob := empty_clob();
    c_mime_boundary VARCHAR2(256) := '-----AABCDEFBBCCC0123456789DE';
    v_len INTEGER;
    v_index INTEGER;
    BEGIN
    FOR x IN (SELECT *
    FROM all_objects
    WHERE ROWNUM < 20)
    LOOP
    v_clob :=
    v_clob
    || x.owner
    || ','
    || x.object_name
    || ','
    || x.object_type
    || ','
    || TO_CHAR(x.created, 'yyyy-mm-dd hh24:mi:ss')
    || UTL_TCP.crlf;
    END LOOP;
    UTL_SMTP.write_data(c, 'MIME-Version: 1.0' || UTL_TCP.crlf);
    UTL_SMTP.write_data(
    c,
    'Content-Type: multipart/mixed; boundary="' || c_mime_boundary || '"' || UTL_TCP.crlf
    UTL_SMTP.write_data(c, UTL_TCP.crlf);
    UTL_SMTP.write_data(
    c,
    'This is a multi-part message in MIME format.' || UTL_TCP.crlf
    UTL_SMTP.write_data(c, '--' || c_mime_boundary || UTL_TCP.crlf);
    --UTL_SMTP.write_data(c, 'Content-Type: text/html;US-ASCII' || UTL_TCP.crlf);
    --Content-Type: image/jpeg
    UTL_SMTP.write_data(
    c,
    'Content-Type: text/html;US-ASCII'
    || UTL_TCP.crlf
    || 'Content-Transfer-Encoding: base64'
    || UTL_TCP.crlf
    -- Set up attachment header
    UTL_SMTP.write_data(
    c,
    'Content-Disposition: attachment; filename="'
    || 'your_file_name.csv'
    || '"'
    || UTL_TCP.crlf
    UTL_SMTP.write_data(c, UTL_TCP.crlf);
    -- Write attachment contents
    v_len := DBMS_LOB.getlength(v_clob);
    v_index := 1;
    WHILE v_index <= v_len
    LOOP
    UTL_SMTP.write_data(c, DBMS_LOB.SUBSTR(v_clob, 32000, v_index));
    v_index := v_index + 32000;
    END LOOP;
    -- End attachment
    UTL_SMTP.write_data(c, UTL_TCP.crlf);
    UTL_SMTP.write_data(c, '--' || c_mime_boundary || '--' || UTL_TCP.crlf);
    EXCEPTION
    WHEN OTHERS THEN
    RAISE_APPLICATION_ERROR( -20110, 'Dwx0110 - R030 - ' || SQLERRM );
    END R040_attach;
    Any help would be appreciated.
    Thank you.

    Hi,
    there are some threads you may find interesting:
    UTL_SMTP mail with attachment( Problem in attaching zip file)
    UTL_SMTP or UTL_MAIL
    Regards.
    Al

  • Can the text that says "See Attachment" that appears in the body of an e-mail be edited?

    When I attach to an e-mail, text that says "See Attachment" appears in the body of the e-mail. I would like to edit this text to say something else. I cannot find where this text is stored in the settings, and I am not even sure if it is generated by thunderbird or by the software that I am using that invokes thunderbird.
    Does anyone know where this text is stored, or if it can be edited?

    There is nothing like what you talk about, so I am unsure what the question is really.
    When you click on write a mail and then add an attachment I see nothing, but an attachment name in the top right corner of the email.

  • How can I have a newsletter I created in PDF appear in the body of an email I send, rather than attach it.

    How can I get a newsletter created in PDF format to appear in the body of an email I send, rather than attach it.

    You cannot. (A few email programs might show it automatically; you cannot stop that either).

  • I just purchased a movie from the iTunes store using iTunes ver. 11.0. The movie downloaded correctly is there on my hard drive but does appear in the iTunes library. How do I get it to appear in the iTunes Movie Library?

    I just purchased a movie from the iTunes store using iTunes ver. 11.0. The movie downloaded correctly is there on my hard drive but does appear in the iTunes library. How do I get it to appear in the iTunes Movie Library?

    Try Handbrake (http://handbrake.fr/), it's good and free

  • I use a gift card and I finished all the redeem steps and they said the email is sent already but I didn't recieve anything so can u resent it please

    I use a gift card and I finished all the redeem steps and they said the email is sent already but I didn't recieve anything so can u resent it please

    Apple - Support - iTunes

  • HT6170 How to reset your Security questions if they say they sent it but you didn't the email. Plz help

    How to reset your Security questions if they say they sent it but you didn't the email. Plz help

    CCheck your spam folder.

  • I downloaded the pages application, to be used like " word", but I can't get if I can use it also to revise documents ....so as to make corrections and they appear on the text. thanks for the help

    I downloaded the "pages"  application, to be used like " word", but I don't know if I can use it also to revise documents ....so as to make corrections and they appear on the text. thanks for the help

    tatarapido wrote:
    I downloaded the "pages"  application, to be used like " word", but I don't know if I can use it also to revise documents ....so as to make corrections and they appear on the text. thanks for the help
    Why repeat the question in the description area? That provides no more information than just leaving the description area blank.
    Yes you can edit documents in Pages. What can you not figure out that you want to do? Have you transfered a document to the iPad and opened it in Pages and tried to edit it?

  • My Ipad has stopped receiving emails today. It has IOS7 on it. The settings are correct but says "connection to the server failed" help!

    My Ipad has stopped receiving emails today. It has IOS7 on it. The settings are correct but says "connection to the server failed" help!
    It is the same accout that has been working find for years and just after I updated the software this has happened. My Mac is still receiving and sending via Outlook with the same account and settings. My Iphone 5C has also stopped and I tried deleting the account and adding again (via exchange as it's an exchange accout) the same way I always do and it won't even recognise it to add the settings.
    So annoying. Can anyone help?

    iOS: Unable to send or receive email
    http://support.apple.com/kb/TS3899
    Can’t Send Emails on iPad – Troubleshooting Steps
    http://ipadhelp.com/ipad-help/ipad-cant-send-emails-troubleshooting-steps/
    iPad Mail
    http://www.apple.com/support/ipad/mail/
     Cheers, Tom

  • Mail under Lion: sent mails do not appear in the sent folder. What is to do?

    Mail under Lion: sent mails do not appear in the sent folder. What is to do?

    897381 wrote:
    So, Where sent messages are stored?
    Because if I go into my email account nothing appears in the outbox?Of course not. Why would it appear in your e-mail reader's outbox when your e-mail reader did not send the e-mail ?
    my Pl/sql looks like:
    BEGIN
    utl_mail.send(sender => '[email protected]',
    recipients => '[email protected]',
    subject => 'Test',
    message => 'HOlix');
    END;And this results in the Oracle database server to contact the mail server and send the mail. Your e-mail client is not part of this process. Your e-mail reader does not know about that e-mail. Your e-mail reader is a client- not a server. It has no reason to know what another e-mail client (your PL/SQL code) send or did not send.
    You want an outbox? You need then to design and code one for your PL/SQL mail client.
    I dont understand what happen?Perhaps you should read up on WHAT a mail (SMTP) server is, HOW it works, and WHAT a PPOP3/IMAP mailbox is, and HOW that works?

  • I have created a form in InDesign, exported to a pdf, created an editable form and saved.  When I open the form and make changes and save, the reopen the changes are there.  If try to email this form as an attachment after editing, the attachment is alway

    I have created a form in InDesign, exported to a pdf, then created an editable form and saved.  When I open the form and make changes and save, then reopen the changes are there.  If try to email this form as an attachment after editing, the attachment is always minus the edits.   ????

    Hi chuck,
    If you ave created the form and then filling it yourself and saving the form, the filled data should be there when you reopen the same form.
    Can you please send the form to me at [email protected]  so that I can have a look.
    Regards,
    Rave

  • In mail, my attachments, both photos and documents appear in the body of the message.  How can I get my attachments to appear as a separate attachment and not as part of the message.  Thanks for your help, Karen.

    In mail, my attachments, both photos and documents, appear in the body of the message.  How can I get my attachments to appear as a separate attachment and not as part of the main message????  Thanks for your help, Karen.

    softwater wrote:
    ...and costs $14.99
    Yep! And if you absolutely need (or think you need) that functionality, it is worth every penny.
    As Don already pointed out, exactly what the recipient sees will depend on how they've set up their machine and what unnecessary 3rd party apps they might've installed to display attachments the way they want.
    In theory, that is true. In practice, Attachment Tamer will cause more of your messages to show up as plain-jane icons on the other end. The problem is, after all, people running Outlook 2003 and 2007. These people likely aren't doing many system modifications.
    If I were you, I'd use the free solutions provided above, save my money and let my recipients decide how they will handle their mail.
    I completely agree.

  • TS1538 I can't connect my ipod4 to itunes 9 on windows vista but it appears in the pc but doesn't appear in itunes  can somebody help

    I can't connect my ipod4 to itunes 9 on windows vista but it appears in the pc but doesn't appear in itunes  can somebody help

    Yes
    http://www.apple.com/itunes/download/

  • How do I add an attachment to an email and not have it show up in the body of the email?

    How do I add an attachment to an email and not have it show up in the body of the email? 

    You can right click or command-click on the image in the email and select "view as icon".
    You can change the default behavior of Mail.app so that it always shows the attachment as the icon:
    open a Terminal window (Applications > Utilities > Terminal)
    at the prompt, type in this (it must be exact, or copy and paste it in if you have trouble typing things precisely):
    defaults write com.apple.mail DisableInlineAttachmentViewing -bool yes
    Then hit return.
    To revert to the previous default (where the attachment is visible in-line), you just enter the same command with "no" instead of "yes" at the end.
    In either case, however, how the viewer of the email sees the attachment (either as an icon or in-line) depends on how their email client is set up, not on how you send it.
    Message was edited by: arthur

  • How can i start to use i chat if it said my password is incorrect and i change it, but still appears that the password is wrong :(

    how can i start to use i chat if it said my password is incorrect and i change it, but still appears that the password is wrong

    Hi,
    AIM
    If this is a Name valid with the AIM servers the password has to be 16 characters or Less.
    The Apple IDs from MobileMe and @Mac.com allow you to create (And prompt your for ) Longer passwords.
    These Names are Valid with the AIM servers but they cannot process the password.
    Use iforgot to Change the password to something shorter.
    Googletalk
    If you are using a Google ID then you have to enter your Google ID as it appears when you log in to the Google Web Mail Page.
    The Mail App seems to allow the Endings (@gmail.com and @googlemail.com) to be used almost interchangeably where as the Jabber Server Google run for Google Talk is stricter (so iChat needs to be precise).
    Also the chat option needs to appear in the Web Mail page.
    If it does not it needs Enabling on you Google Account settings page.
    8:10 PM      Tuesday; July 5, 2011
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb( 10.6.8)
     Mac OS X (10.6.7),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

Maybe you are looking for

  • ITunes Match fails to upload songs

    I am posting this as information for other hapless iTunes Match users with the same problem. When I first subscribed to iTunes Match it successfully completed Steps 1 and 2 but failed to complete Step 3, where it uploads songs and artwork not found i

  • Emails are not showing to receipt person in genuine format

    Whenever, I send an email to anyone from my Thunderbird to MS outlook. The receiving person does not get my email in proper format i.e. I had send an email to my client and got reply from client that, email is not in proper format. They gave me scree

  • Block diagram out of... block diagram

    Hi, I need your help. Im the wrong person to this job, but I have to do this, so I'm dependent on your help. I need to explain how the LabView program (pasted below) works, but I don't understand it by myself I would like to ask if someone can create

  • Newbie Adobe Captivate question

    :embarrassment; I assume I am doing something wrong and just don't realize - here is my issue. I have 2 ***.exe files that are training files created in captivate that I want to watch. They sort of play but don't. I see the starting screen but I don'

  • Add pictures to my gallery

    I just got a replacement phone, how to I add pictures to my Samsung galaxy s4 gallery from the Verizon cloud?