Utl_mail attachments
I'm using Oracle 10g, Linux Redhat.
I spooled a query to the '/tmp/errlog.txt' and want to email the results.
I'm using this statement to email the results.
BEGIN
EXECUTE IMMEDIATE 'ALTER SESSION SET smtp_out_server = ''smtp.fmi.com:25''';
UTL_MAIL.SEND_ATTACH_VARCHAR2(
sender => '[email protected]',
recipients => '[email protected]',
subject => 'PR1 Trigger Error Log',
message => 'Attached is the PR1 Trigger Error Log',
attachment => '/tmp/errlog.txt');
END;
I'm getting the email but the attachment?
Any advice?
Thanks in advance.
The parameters that need to be provided are:
attachment
The manual says +"Text attachment+". In other words, the contents of the text file.
att_mime_type
Specifies the type of attachment. Default is plain text. Mime type can be html text, or in the case of binary attachments, pictures, video, audio and so on.
att_filename
What the attachment is called (e.g. filename). This does NOT mean point to a file somewhere on local disk (or the network) and the file automagically attaches itself to the e-mail.
The result of this is a Mime body that contains both e-mail contents and attachment contents. Have a look at {message:id=4402801}. It shows how the actual Mime body (that constitutes the e-mail header, message and attachment) looks like.
This is what you need to create using code... and then deliver using SMTP. The UTL_MAIL package is a very primitive (and poorly written) interface that creates such a Mime body for you and delivers it for you by calling the UTL_SMTP package.
I suggest that you familiarise yourself with the basics of Mime and how attachments works and what the formatting requirements are. The easiest is crafting the type of e-mail that you want to send using your favourite mail reader and then e-mail that to yourself. After receiving that e-mail, look at the "source" view (raw format view) of that e-mail to see how it looks like.
And what you see is what you will need to create - using UTL_MAIL to do it, or (even better), coding it yourself (e.g. HTML report e-mails with gif attachments that serve as embedded graphics in the e-mail, and so on).
It is not that difficult. It simply requires basic understanding and not assuming that a parameter does something that is obviously does not do.
Similar Messages
-
Utl_mail - how many attachments can i send in one e-mail
Hello
I try to find out if is possible to send more than one attachment in e-mail using utl_mail from 10g...If is can you offer me some guidence?
Thank you,
OanaThe only practical limits on the number of attachments that can be sent in an email are dictated not by Oracle, but by the individual SMTP servers you are dealing with. Many SMTP servers limit the total size of an email (e.g. 4 Megs) which would effectively limit the number of attachments you can send. However, this is only a total size limit so you could have many small attachments or just a couple of large attachments, or anything in between.
Then again some SMTP servers may have no such limits. -
Sending e-mail attachments with utl_mail.
Hello guys i would like to add an attachment to an e-mail using utl_mail
I have gotten this part done without a problem.
My problem now is that i have to loop a table and make the contents of the table an attachment to the e-mail.
So here is what i have so far.
DECLARE
b64 VARCHAR2 (512) := 'WELL THIS IS A WHOLE LOT OF DATA!'; -- etc., as above
txt VARCHAR2 (512) := 'Dear Scott: ...'; -- etc., as above
BEGIN
UTL_MAIL.send_attach_varchar2 (sender => 'xxxx'
, recipients => [email protected].'
, MESSAGE => txt
, subject => 'Attachment demo'
, att_mime_type => 'application/x-gzip'
, attachment => b64
, att_inline => TRUE
, att_filename => 'hugo.txt'
END;
/and i have a loop like this.
for rec in
(SELECT
FWTMP_REGPO_INV_NUM,
FWTMP_REGPO_ERR_BAD_FUND,
FWTMP_REGPO_ERR_BAD_ORGN,
FWTMP_REGPO_ERR_BAD_PROG,
FWTMP_REGPO_ERR_BAD_ACCT,
FWTMP_REGPO_ERR_AMT_MORE,
FWTMP_REGPO_ERR_NOPIDM_MATCH,
FWTMP_REGPO_ERR_QTY_MORE,
FWTMP_REGPO_ERR_ENC_LESS,
FWTMP_REGPO_ERR_NOFP_MATCH,
FWTMP_REGPO_ERR_NOFY_MATCH,
FWTMP_REGPO_FTVFSYR_FSYR,
FWTMP_REGPO_VEND_NUM,
FWTMP_REGPO_ERR_INV_FOUND,
FWTMP_REGPO_INV_AMT,
FWTMP_REGPO_PO,
fwtmp_regpo_credit_memo
FROM FWTMP_REGPO_INTRFACE
WHERE FWTMP_REGPO_ERR_IND = 'Y')
loop
utl_file.put_line(f,rpad(NVL('Invoice Number: '||rec.fwtmp_regpo_inv_num,'0'||' '),200)||CHR(13)
||rpad(NVL('Fund Error: '||rec.FWTMP_REGPO_ERR_BAD_FUND,'0'||' '),200)||CHR(13)
||rpad(NVL('Org Error: '||rec.FWTMP_REGPO_ERR_BAD_ORGN,'0'||' '),200)||CHR(13)
||rpad(NVL('Program Error: '||rec.FWTMP_REGPO_ERR_BAD_PROG,'0'||' '),200)||CHR(13)
||rpad(NVL('Account Error '||rec.FWTMP_REGPO_ERR_BAD_ACCT,'0'||' '),200)||CHR(13)
||rpad(('Amount Error: '||rec.FWTMP_REGPO_ERR_AMT_MORE||'0'),200)||CHR(13)
||rpad(('Vendor Error: '||rec.FWTMP_REGPO_ERR_NOPIDM_MATCH||'0'),200)||CHR(13)
||rpad(('Quantity Error: '||rec.FWTMP_REGPO_ERR_QTY_MORE||'0'),200)||CHR(13)
||rpad(('Encumbrance Error: '||rec.FWTMP_REGPO_ERR_ENC_LESS||'0'),200)||CHR(13)
||rpad(NVL('period Error: '||rec.FWTMP_REGPO_ERR_NOFP_MATCH,'0'||' '),200)||CHR(13)
||rpad(NVL('Fiscal Year Error :'||rec.FWTMP_REGPO_ERR_NOFY_MATCH,'0'||' '),200)||CHR(13)
||rpad(NVL('Vendor: '||rec.FWTMP_REGPO_VEND_NUM,'0'||' '),200)||CHR(13)
||rpad(NVL('Invoice Error :'||rec.FWTMP_REGPO_ERR_INV_FOUND,'0'||' '),200)||CHR(13)
||rpad(NVL('Amount: '||rec.FWTMP_REGPO_INV_AMT,'0'||' '),200)||CHR(13)
||rpad(NVL('Po: '||rec.FWTMP_REGPO_PO,'0'||' '),200)||CHR(13)
||rpad(NVL('Credit memo: '||rec.fwtmp_regpo_credit_memo,'0'||' '),200)
||CHR(13)||'-------------------------------------------------------------------------------------------'||CHR(13));
end loop;My challenge is simplly how to get the contents of the loop to the b64 variable. Any help would be greatly appreciated.
Thanks
Edited by: mlov83 on Sep 18, 2012 7:01 AMmlov83 wrote:
I guess you have never been confused or frustuated. :-). That is why drinking copious amounts of coffee is important.
A simple example of code goes a long way.
SEND_ATTACH_VARCHAR2() call is explained in the documentation. Numerous source code examples can be easily found. Thus my criticism.
The basic concept is - the attachment parameter contains the contents (e.g. file content, text content, image contents) and the filename parameter names that contents.
Keep in mind that the document clearly states that the attachment data types are varchar2 and raw - both which are limited to 32KB. This means that larger attachment sizes will fail and that you need to use UTL_SMTP instead. Which is also documented in the same reference guide. And for which there are also a lot of examples. -
Multiple attachments using UTL_MAIL?
Hi all,
Does anyone know if its possible to attach multiple documents to an email and send them using the UTL_MAIL package. I am able to send one attachment stored in the server but would like to attach multiple files if possible. Any help would be greatly appreciated.
Regards,
RayHi all,
Does anyone know if its possible to attach multiple documents to an email and send them using the UTL_MAIL package. I am able to send one attachment stored in the server but would like to attach multiple files if possible. Any help would be greatly appreciated.
Regards,
Ray -
How to attach multiple files in UTL_MAIL.SEND_ATTACH_VARCHAR2 method
Hi all ,
I had written a pl/sql where it will write multiple csvs i.e. a.csv,b.csv,c.csv,d.csv to a location using UTL_FILE to reports folder .
How do i attach a.csv,b.csv,c.csv,d.csv into a single mail ??
UTL_MAIL.send_attach_raw (sender => '[email protected]',
recipients => 'recepient.com.sg',
subject => 'Reports',
MESSAGE => 'Reports are attached above',
mime_type => 'text/html; charset=UTF8',
attachment => a.csv,
att_inline => FALSE,
att_filename => file1
Edited by: 907812 on 12-Jan-2012 23:03
Edited by: 907812 on 12-Jan-2012 23:03
Edited by: 907812 on 12-Jan-2012 23:04
Edited by: 907812 on 12-Jan-2012 23:04UTL_MAIL does not work like that - you pointing to an external file and telling it to grab it and attached it to your e-mail.
If you refer to the manual, the attachment parameter specifies it must contain the contents of the file.
So your code needs to open the file. Your code needs to read the contents of the file. Your code needs to close the file. Your code needs to supply the contents text to UTL_MAIL via the attachment parameter.
And as there is only a single attachment parameter, only a single file's contents can be supplied as attachment.
Multiple attachments? Then you need to do what UTL_MAIL does. You need to write code that creates a valid e-mail Mime body. The Mime body must allow for multiple attachment. The Mime body needs to be delivered as an e-mail via the UTL_SMTP package. -
Sending email with multiple attachments
Hi forum,
I am able to send email with a single attachment using maildemo.sql from: http://www.oracle.com/technology/sample_code/tech/pl_sql/htdocs/Utl_Smtp_Sample.html
But now I am trying to send email with more than 1 attachment and it does not work. My code that calls the above mentioned package is as follows:
<code>
PROCEDURE send (
psender VARCHAR2,
precipients VARCHAR2,
pcc VARCHAR2,
pbcc VARCHAR2,
psubject VARCHAR2,
pmessage VARCHAR2,
pnumattach NUMBER) -- The number of attachments that need to be sent
IS
p_blob BLOB;
p_filename VARCHAR2(200);
p_filetype VARCHAR2(200);
p_currSeq NUMBER;
conn utl_smtp.CONNECTION;
i NUMBER;
j NUMBER;
len NUMBER;
BEGIN
IF pnumattach > 1
THEN
conn := SEND_EMAIL_HELPER.begin_mail(
sender => psender,
recipients => precipients,
subject => psubject,
mime_type => send_email_helper.MULTIPART_MIME_TYPE);
j := 0;
SELECT seq_attach_transact_id.CURRVAL INTO p_currSeq FROM dual; -- seq_attach_transact_id is a primary key that identifies every single attachment in the table
WHILE (j < pnumattach) LOOP
p_currSeq := p_currSeq - j;
SELECT blob_content INTO p_blob FROM wwdoc_document WHERE transaction_id = p_currSeq;
SELECT name INTO p_filename FROM wwdoc_document WHERE transaction_id = p_currSeq;
SELECT mime_type INTO p_filetype FROM wwdoc_document WHERE transaction_id = p_currSeq;
SEND_EMAIL_HELPER.begin_attachment(
conn => conn,
mime_type => p_filetype,
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 + SEND_EMAIL_HELPER.MAX_BASE64_LINE_WIDTH < len)THEN
UTL_SMTP.Write_Raw_Data (conn,
UTL_ENCODE.Base64_Encode(
DBMS_LOB.SUBSTR(p_blob, SEND_EMAIL_HELPER.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 + SEND_EMAIL_HELPER.MAX_BASE64_LINE_WIDTH;
END LOOP;
SEND_EMAIL_HELPER.end_attachment(conn => conn);
END LOOP;
SEND_EMAIL_HELPER.attach_text(
conn => conn,
data => pmessage,
mime_type => 'text/html');
SEND_EMAIL_HELPER.end_mail( conn => conn );
ELSE
utl_mail.send(psender,precipients,pcc,pbcc,psubject,pmessage);
END IF;
END send;
</code>
Can anyone please tell me where am i going wrong.
Message was edited by:
MonkThe easiest is to send an e-mail with multiple attachments to yourself and then view the message in raw to see how it is formatted - how the boundaries work. what the boundary headers are, etc.
Then you use that as a template for your PL/SQL code to generate a MIME body for an e-mail that has multiple attachments.
To debug.. have your PL/SQL code send sample e-mails with multiple attachment to your account, view it in raw format and compare that to the original format you've based your template on.
And none of this is really a PL/SQL issue.. it is all about formatting a valid MIME message for an e-mail. -
Setting up directory object for emailing attachments
Hi,
I am having trouble trying to send emails with attachments. I have downloaded and created the the demo_mail package and the pdf_mail procedure. I also have the send_email_attach procedure using utl_mail.
I am not sure, or familiar on setting up the directory object. I don't have privileges to do this so I need to understand exactly what needs to be done so I could relay it to my dba.
In the Send_email_attach procedure there is this code
"fHandle := UTL_FILE.FOPEN('/Source/Apps/prod/reports', 'mypdf.pdf', 'r');" I put the directory path the file is in as the first argument and the name of my pdf in the second one. When I run it, it gives me an error:
ORA-20001: The following error has occured : ORA-29280: invalid directory path
I'm thinking I need the directory object in the first argument? Is this correct. And then do I put the file in the directory path that the directory object points to? and keep as the second argument?
using the pdf_mail procedure it sends the email but the attachment in the email is bad. Acrobat just says: Acrobat reader could not open '~6034454.pdf' because it is either not a supported file type or because the file has been damaged (for example, it was sent as an email attachment and wasn't correctly formated).
This is the code I use to call it:
pdf_mail('myemail',
'another email',
'This is a test',
'Hope it works',
'/Data/oracle/product/10g__BI/tools/web/icons/myicons/mypdf.pdf',
EMPTY_BLOB());
I am not sure what to put in the last two arguments. In the next to last argument I put the path where the file is and in the last argument I put EMPTY_BLOB() call. If I put the name of the pdf in quotes it gives me an error ORA-06550: wrong number or types of arguments in call to pdf_mail.
I'm not sure how to reference the files or the directory.
any help would be greatly appreciated.
thanksYou need to use a directory object to do this properly. If you don't have privileges then get them...
The UTL_FILE_DIR parameter has been deprecated by oracle in favour of direcory objects because of it's security problems.
The correct thing to do is to create a directory object e.g.:
CREATE OR REPLACE DIRECTORY mydir AS 'c:\myfiles';Note: This does not create the directory on the file system. You have to do that yourself and ensure that oracle has permission to read/write to that file system directory.
Then, grant permission to the users who require access e.g....
GRANT READ,WRITE ON DIRECTORY mydir TO myuser;Then use that directory object inside your FOPEN statement e.g.
fh := UTL_FILE.FOPEN('MYDIR', 'myfile.txt', 'r');Note: You MUST specify the directory object name in quotes and in UPPER case for this to work as it is a string that is referring to a database object name which will have been stored in uppercase by default. -
UTL_SMTP or UTL_MAIL
Hi All,
I need to send message from OA Framework through pl/sql procedure. Our database is 10g.
What would you recommend to me UTL_SMTP or UTL_Mail. I have a code in which i able to send mail but how to send mail with attachment.
If anyone can arrange some working code of it then it is really appreciable.
Thanks
--AjayHmm... Then I can share with you source of procedure
create or replace procedure email_files(from_name varchar2,
to_names varchar2,
subject varchar2,
message varchar2 default null,
html_message varchar2 default null,
cc_names varchar2 default null,
bcc_names varchar2 default null,
filename1 varchar2 default null,
filetype1 varchar2 default ‘text/plain’,
filename2 varchar2 default null,
filetype2 varchar2 default ‘text/plain’,
filename3 varchar2 default null,
filetype3 varchar2 default ‘text/plain’)
is
— Change the SMTP host name and port number below to your own values,
— if not localhost on port 25:
smtp_host varchar2(256) := ‘####################’;
smtp_port number := 25;
boundary constant varchar2(256) := ‘CES.Boundary.DACA587499938898′;
recipients varchar2(32767);
directory_path varchar2(256);
file_name varchar2(256);
crlf varchar2(2):= chr(13) || chr(10);
mesg varchar2(32767);
conn UTL_SMTP.CONNECTION;
type varchar2_table is table of varchar2(256) index by binary_integer;
file_array varchar2_table;
type_array varchar2_table;
i binary_integer;
PROCEDURE split_path_name(file_path IN VARCHAR2, directory_path OUT VARCHAR2,
file_name OUT VARCHAR2) IS
pos number;
begin
— Separate the filename from the directory name
pos := instr(file_path,’/',-1);
if pos = 0 then
pos := instr(file_path,’\',-1);
end if;
if pos = 0 then
directory_path := null;
else
directory_path := substr(file_path,1,pos - 1);
end if;
file_name := substr(file_path,pos + 1);
end;
— Procedure to append a file’s contents to the e-mail
PROCEDURE append_file(directory_path IN VARCHAR2, file_name IN VARCHAR2,
file_type IN VARCHAR2, conn IN OUT UTL_SMTP.CONNECTION) IS
generated_name varchar2(30) := ‘CESDIR’ || to_char(sysdate,’HH24MISS’);
directory_name varchar2(30);
file_handle utl_file.file_type;
bfile_handle bfile;
bfile_len number;
pos number;
read_bytes number;
line varchar2(1000);
data raw(200);
my_code number;
my_errm varchar2(32767);
begin
begin
— Grant access to the directory, unless already defined, and open
— the file (as a bfile for a binary file, otherwise as a text file).
begin
line := directory_path;
select dd.directory_name into directory_name from dba_directories dd
where dd.directory_path = line and rownum = 1;
exception
when no_data_found then
directory_name := generated_name;
end;
if directory_name = generated_name then
execute immediate ‘create or replace directory ‘ || directory_name ||
‘ as ”’ || directory_path || ””;
execute immediate ‘grant read on directory ‘ || directory_name ||
‘ to public’;
end if;
if substr(file_type,1,4) != ‘text’ then
bfile_handle := bfilename(directory_name,file_name);
bfile_len := dbms_lob.getlength(bfile_handle);
pos := 1;
dbms_lob.open(bfile_handle,dbms_lob.lob_readonly);
else
file_handle := utl_file.fopen(directory_name,file_name,’r');
end if;
— Append the file contents to the end of the message
loop
— If it is a binary file, process it 57 bytes at a time,
— reading them in with a LOB read, encoding them in BASE64,
— and writing out the encoded binary string as raw data
if substr(file_type,1,4) != ‘text’ then
if pos + 57 - 1 > bfile_len then
read_bytes := bfile_len - pos + 1;
else
read_bytes := 57;
end if;
dbms_lob.read(bfile_handle,read_bytes,pos,data);
utl_smtp.write_raw_data(conn,utl_encode.base64_encode(data));
pos := pos + 57;
if pos > bfile_len then
exit;
end if;
— If it is a text file, get the next line of text, append a
— carriage return / line feed to it, and write it out
else
utl_file.get_line(file_handle,line);
utl_smtp.write_data(conn,line || crlf);
end if;
end loop;
— Output any errors, except at end when no more data is found
exception
when no_data_found then
null;
when others then
my_code := SQLCODE;
my_errm := SQLERRM;
dbms_output.put_line(’Error code ‘ || my_code || ‘: ‘ ||
my_errm);
end;
— Close the file (binary or text)
if substr(file_type,1,4) != ‘text’ then
dbms_lob.close(bfile_handle);
else
utl_file.fclose(file_handle);
end if;
if directory_name = generated_name then
execute immediate ‘drop directory ‘ || directory_name;
end if;
end;
begin
— Load the three filenames and file (mime) types into an array for
— easier handling later
file_array(1) := filename1;
type_array(1) := filetype1;
— Open the SMTP connection and set the From and To e-mail addresses
conn := utl_smtp.open_connection(smtp_host,smtp_port);
utl_smtp.helo(conn,smtp_host);
recipients := from_name;
utl_smtp.mail(conn,recipients);
recipients := to_names;
utl_smtp.rcpt(conn,recipients);
utl_smtp.open_data(conn);
— Build the start of the mail message
mesg := ‘Date: ‘ || TO_CHAR(SYSDATE,’dd Mon yy hh24:mi:ss’) || crlf ||
‘From: ‘ || from_name || crlf ||
‘Subject: ‘ || subject || crlf ||
‘To: ‘ || to_names || crlf;
mesg := mesg || ‘Mime-Version: 1.0′ || crlf ||
‘Content-Type: multipart/mixed; boundary=”‘ || boundary || ‘”‘ ||
crlf || crlf ||
‘This is a Mime message, which your current mail reader may not’ || crlf ||
‘understand. Parts of the message will appear as text. If the remainder’ || crlf ||
‘appears as random characters in the message body, instead of as’ || crlf ||
‘attachments, then you”ll have to extract these parts and decode them’ || crlf ||
‘manually.’ || crlf || crlf;
utl_smtp.write_data(conn,mesg);
— Write the text message or message file, if any
if message is not null then
mesg := ‘–’ || boundary || crlf ||
‘Content-Type: text/plain; name=”message.txt”; charset=US-ASCII’ ||
crlf ||
‘Content-Disposition: inline; filename=”message.txt”‘ || crlf ||
‘Content-Transfer-Encoding: 7bit’ || crlf || crlf;
utl_smtp.write_data(conn,mesg);
if substr(message,1,1) = ‘/’ then
split_path_name(message,directory_path,file_name);
append_file(directory_path,file_name,’text’,conn);
utl_smtp.write_data(conn,crlf);
else
utl_smtp.write_data(conn,message || crlf);
end if;
end if;
— Append the files
if file_array(1) is not null then
split_path_name(file_array(1),directory_path,file_name);
— Generate the MIME boundary line according to the file (mime) type
— specified.
mesg := crlf || ‘–’ || boundary || crlf;
if substr(type_array(1),1,4) != ‘text’ then
mesg := mesg || ‘Content-Type: ‘ || type_array(1) ||
‘; name=”‘ || file_name || ‘”‘ || crlf ||
‘Content-Disposition: attachment; filename=”‘ ||
file_name || ‘”‘ || crlf ||
‘Content-Transfer-Encoding: base64′ || crlf || crlf ;
else
mesg := mesg || ‘Content-Type: application/octet-stream; name=”‘ ||
file_name || ‘”‘ || crlf ||
‘Content-Disposition: attachment; filename=”‘ ||
file_name || ‘”‘ || crlf ||
‘Content-Transfer-Encoding: 7bit’ || crlf || crlf ;
end if;
utl_smtp.write_data(conn,mesg);
— Append the file contents to the end of the message
append_file(directory_path,file_name,type_array(1),conn);
utl_smtp.write_data(conn,crlf);
end if;
— Append the final boundary line
mesg := crlf || ‘–’ || boundary || ‘–’ || crlf;
utl_smtp.write_data(conn,mesg);
— Close the SMTP connection
utl_smtp.close_data(conn);
utl_smtp.quit(conn);
end;
/ Then execute
exec email_files(from_name=>’[email protected]’,to_names=>’[email protected]’, subject=> ‘mail subject’,filename1=>’test.tar’, filetype1=> ‘application/x-tar’);- - - - - - - - - - - - - - - - - - - - -
Kamran Agayev A. (10g OCP)
http://kamranagayev.wordpress.com -
ORA-06512 errors (utl_mail)
Hi,
I want to send mail using utl_mail.
I use Oracle 10g and prepare database go through this command:
CONN sys/password AS SYSDBA
@$ORACLE_HOME/rdbms/admin/utlmail.sql
@$ORACLE_HOME/rdbms/admin/prvtmail.plb
GRANT EXECUTE ON UTL_MAIL TO any_user;
ALTER SYSTEM SET smtp_out_server='smtp.gmail.com';
SHUTDOWN IMMEDIATE
STARTUP
Then I login to any_user and try send mail:
BEGIN
UTL_MAIL.send(sender => '[email protected]',
recipients => '[email protected]',
subject => 'This is a test :)',
message => 'Yeah, it worked! :)');
END;
But this give me this errors:
ERROR at line 1:
ORA-29279: SMTP permanent error: 530 5.7.0 Must issue a STARTTLS command first
f7sm989291nfh.25
ORA-06512: at "SYS.UTL_SMTP", line 21
ORA-06512: at "SYS.UTL_SMTP", line 99
ORA-06512: at "SYS.UTL_SMTP", line 222
ORA-06512: at "SYS.UTL_MAIL", line 407
ORA-06512: at "SYS.UTL_MAIL", line 594
ORA-06512: at line 2
Or I try this procedure (find on ask Tom site):
create or replace PROCEDURE send_mail (p_sender IN VARCHAR2, p_recipient IN VARCHAR2, p_message IN VARCHAR2) as
l_mailhost VARCHAR2(255) := 'smtp.gmail.com';
l_mail_conn utl_smtp.connection;
BEGIN
l_mail_conn := utl_smtp.open_connection(l_mailhost, 465);
utl_smtp.helo(l_mail_conn, l_mailhost);
utl_smtp.mail(l_mail_conn, p_sender);
utl_smtp.rcpt(l_mail_conn, p_recipient);
utl_smtp.open_data(l_mail_conn );
utl_smtp.write_data(l_mail_conn, p_message);
utl_smtp.close_data(l_mail_conn );
utl_smtp.quit(l_mail_conn);
end;
begin
send_mail( '[email protected]', '[email protected]', 'Hello :)' );
end;
But there SQL*Plus hang up and I must close application :/
Any suggestion for this??The e-mail still needs to be delivered. A local SMTP server will still need to connect to another SMTP server in order to deliver the e-mail to the recipient.
If that local SMTP server can make that connection to that "other" SMTP server, why not simply do it from PL/SQL instead? A lot simpler than configuring something like sendmail as your local SMTP server.
> It's not Oracle site but PSOUG was great authority for me.
Indeed an excellent site, but I doubt that UTL_SMTP will be deprecated. Just like UTL_SMTP did not deprecate UTL_TCP.
Each one builds on the other, providing a higher level abstraction interface. UTL_TCP is needed to talk tcp to the SMTP server. UTL_SMTP uses that to talk SMTP over tcp. UTL_MAIL needs SMTP to deliver auto formatted Mime bodies as e-mail.
Maybe what PSOUG implied that from a programming perspective, you should deprecate using UTL_SMTP and instead use the much easier abstraction API called UTL_MAIL.
It does not make a lot of sense for application code to use UTL_SMTP directly, given the higher level mail API provided by UTL_MAIL.
At the same time, it make sense for one to write your own UTL_MAIL wrapper, extend the abilities of UTL_MAIL (such as supporting multiple attachments, etc) and use UTL_SMTP to perform the delivery. -
UTL_MAIL: Send_Attach_Raw / Attachement-Size?
Just two simple question :-)
I want to use the UTL_Mail Package from 10g to send emails with attachements.
Question 1: Can I attach more than one attachment or must I "zip" the files to one file before I can use the package?
Question 2: What is the maximum size for an attachement?
The input-parameter for the attachement in the Send_Attach_Row Procedure is of datatype RAW.
Does this mean an attachement can not be > 32K ???
If not, how can I send attachements > 32K ???
Regards
UdoI've not looked at the 10g UTL_MAIL package yet, but I use the UTL_SMTP package provided with 9i (probably also available in 10g). On OTN ther's a demo mail package available which you can alter after studying it. I've added/modified a procedure to that package:
/* Write a binary attachment (BLOB) */
PROCEDURE ATTACH_BASE64
(P_CONN IN OUT NOCOPY UTL_SMTP.connection
,P_DATA IN BLOB
,P_MIME_TYPE IN VARCHAR2 := 'application/octet'
,P_INLINE IN BOOLEAN := TRUE
,P_FILENAME IN VARCHAR2 := NULL
,P_LAST IN BOOLEAN := FALSE
IS
i PLS_INTEGER;
len PLS_INTEGER;
BEGIN
BEGIN_ATTACHMENT(p_conn, p_mime_type, p_inline, p_filename, 'base64');
-- Split the Base64-encoded attachment into multiple lines
i := 1;
len := DBMS_LOB.getLength(p_data);
WHILE (i < len) LOOP
IF(i + MAX_BASE64_LINE_WIDTH < len)THEN
UTL_SMTP.Write_Raw_Data (p_conn
, UTL_ENCODE.Base64_Encode(
DBMS_LOB.Substr(p_data, MAX_BASE64_LINE_WIDTH, i)
ELSE
UTL_SMTP.Write_Raw_Data (p_conn
, UTL_ENCODE.Base64_Encode(
DBMS_LOB.Substr(p_data, (len - i), i)
END IF;
UTL_SMTP.Write_Data(p_conn, UTL_TCP.CRLF);
i := i + MAX_BASE64_LINE_WIDTH;
END LOOP;
END_ATTACHMENT(p_conn, p_last);
END;As you can see you will need the demo mail package. You can call this procedure to add several binary attachments with no limit. And I'm sure you somehow can put this in use with the new UTL_MAIL package.
Hope this helps,
Michiel -
10G UTL_MAIL.SEND and message bigger than a LONG variable ?
Hi,
Is it possible to send out a message containing more that 32767 characters (LONG) using 10G UTL_MAIL.SEND. I have to send a big HTML report (inline).
Thank'sHi
its true we cannot use UTL_MAIL package for sending mails with Attachments as it can be used only for attachments of size less than 32KB. For higher sizes i referred Metalink an found the below info regarding UTL_SMTP.
This is the doc Id
Doc ID: Note:357385.1
Doc ID: Note:414062.1
Doc ID: Note:334734.1
Doc ID: Note:302943.1
Hope this docs helps u in your findings.
however, i have dropped my plans to send mail with attachments as mailbox has size limits and my files can be very big. SO, i would instead store the file in to a customr notified location and send him a mail about the presence of the file. I know this is not the right approach but i cudnt find a better approach than this. If any one can fin a better solution plz post it here.
Regards
Vibhuti -
1- How can i attach a text file, image file or other MS Office documents via UTL_SMTP package.
2- How can i send CC or BCC through UTL_SMTP.Use UTL_MAIL for attachments.
http://www.psoug.org/reference/utl_mail.html -
Hi,
Can anyone confirm if the UTL_MAIL package is deployed with XE? I have installed the latest version of XE, in Chapter 5 of the "Oracle® Database Express Edition 2 Day Developer Guide
10g Release 2 (10.2)" there is a table listing the available packages:
http://download-uk.oracle.com/docs/cd/B25329_01/doc/appdev.102/b25108/xedev_programs.htm#BABIFBGE
UTL_MAIL is listed there, but a query on the DBA_OBJECTS view for it does not return any rows. Any pointers would be greatly appreciated.
The reason I am interested in this package is that it has to ability to add attachments to mail messages, something the supplied Apex packages on XE cannot do.
thanks,
stuartLooks like the install does not build it by default. The utlmail.sql (spec) & prvtmail.plb (body) file's are in the %ORACLE_HOME%\RDBMS\ADMIN directory. You just need to connect as sys & run both scripts. You also need to specify the smtp server in the spfile, using:
alter system set smtp_out_server = '<ip-address:port' scope=Both; -
Quicklook downloads attachments to wrong folder
Tried searching for this but came up empty so I want to try and see if others are wondering why Quicklook in Mail downloads the attachment to a folder different from the one I specified as my Downloads folder, in my case, my Desktop Folder.
I receive an email with an attachment. I use Quicklook (be it the button on the header, pressing the spacebar, or using the contextual menu) to view the file at which time Mail first downloads the attachment. However, it always downloads it to the User/Library/Mail Downloads folder instead of the Downloads folder I selected in Preferences.
Does anyone else have this "problem?" If so, is there a setting for this I am not seeing? I hope it can be changed because I habitually use Quicklook now and that Mail Downloads folder can fill up rather quickly without realizing as I download attachments to specific places after the fact, causing double copies on my hard drive. Hope someone can help.Andew, thanks for the reply, however, I am with "gumsie" on this one. Like gumsie stated, if I save the attachment using the button in the header or contextual menu, and open the file from there, then there is no real problem. However, if I Open or Quicklook the attachment directly in the Message Window, then Mail does save a copy of the attachment to the /Library/Mail Downloads folder no matter if I saved the attachment before or if I have a Downloads folder set in Preferences. This is what I think is an odd bit of behavior from the software.
In the end, I think there is really nothing we can do about this and the best thing for me to do is just download the attachment to my set Downloads folder, and Open/Quicklook it from there in order to avoid multiple copies on my drive (I deal with largish files so cumulatively multiple copies just take up too much space on the drive). It's too bad Apple hasn't addressed this.
Thank you both for your input. At least now I know that A) I'm not alone in this and B) I just have to change my habits. -
I was previewing attachments, pictures .png files, at least 30 or 40 of them and then all of a sudden I got an error message that
"this file cannot be previewed. try opening the file in the program in which it was created" and now I can't preview even the pictures I previously did.
What happened? What can I do?Hi,
This issue can be caused by the temporary files, sometimes Outlook may not handle its temporary file folders well, so cleaning out the folder may solve this issue.
We can follow the steps in this link to empty the temp folder:
http://www.howto-outlook.com/faq/securetemp.htm
Hope this can help you.
Regards,
Melon Chen
TechNet Community Support
Maybe you are looking for
-
Error in Configuring the EBS Adapter for WebCenter
Hi All, when I'm configuring EBS Adapter for Web Center I'm getting the below Error while running the sql script AXF_EBS_SOLUTION_DATA.sql ,and I check the AXF_CONFIGS table is not available in db schema, not sure when this table will create. please
-
I used a Postcard viewer script in Lightroom (also available as add-on in Photoshop) which creates a folder with the html coded page and all other files needed to view the page. Is there a way to add that to an existing page on a website. I would lik
-
Hi All, I have a query region with result table, it results the data upon search creteria. each row have a update icon where user can navigates to update page to edit the information. So when user gets back to search page and clicks on clear button o
-
Attaching image to email?
If I'm in the middle of writing an email, or have finished it and now ready to send, how do I attach one or more images from Photos please? Terry, UK
-
Imported images have jagged edges when scaled down
Perhaps I'm missing something really obvious (like the quality thing in the After Effects timeline), but I imported a Photoshop image, a logo, scaled it down to 15%, and it has jagged edges. Ditto for a TIFF version of same. Starting resolution is pl