How can I send attachment ?
Regards, Gj.
-----Original Message-----
From: tpepling [mailto:oracledba-ezmlmshield-x71217791.[Email address protected]
Sent: Wednesday, September 08, 2004 8:22 PM
To: LazyDBA Discussion
Subject: RE: Email from oracle
Hope this helps.
SET TERMOUT ON
CREATE OR REPLACE PROCEDURE SEND_MAIL (
p_TO IN VARCHAR2,
p_CC IN VARCHAR2 := NULL,
p_SUBJECT IN VARCHAR2,
p_MESSAGE IN VARCHAR2
)
AS
-- ------------------------------------------------------------
-- Must change the value of v_MAILHOST for your site.
-- ------------------------------------------------------------
--v_MAILHOST VARCHAR2(30) := '9.66.9.66';
v_MAILHOST VARCHAR2(30) := UTL_INADDR.GET_HOST_NAME;
v_MAIL_CONN UTL_SMTP.CONNECTION;
v_SENDER VARCHAR2(50);
v_HEADER VARCHAR2(400);
v_CRLF VARCHAR2(2) := CHR(13)||CHR(10);
BEGIN
v_SENDER := '[Email address protected]
v_MAIL_CONN := UTL_SMTP.OPEN_CONNECTION(v_MAILHOST, 25);
UTL_SMTP.HELO (v_MAIL_CONN, v_MAILHOST);
UTL_SMTP.MAIL (v_MAIL_CONN, v_SENDER);
UTL_SMTP.RCPT (v_MAIL_CONN, p_TO);
v_HEADER :=
'Date: '|| TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' )|| v_CRLF ||
'From: ' || v_SENDER || v_CRLF ||
'Subject: ' || p_SUBJECT || v_CRLF ||
'To: ' || p_TO || v_CRLF ||
'Cc: ' || p_CC || v_CRLF ||
''|| v_CRLF
;
UTL_SMTP.OPEN_DATA (v_MAIL_CONN);
UTL_SMTP.WRITE_DATA (v_MAIL_CONN, v_HEADER); -- message header
UTL_SMTP.WRITE_DATA (v_MAIL_CONN, UTL_TCP.CRLF||p_MESSAGE); -- message
body
UTL_SMTP.CLOSE_DATA (v_MAIL_CONN);
UTL_SMTP.QUIT (v_MAIL_CONN);
EXCEPTION
WHEN UTL_SMTP.TRANSIENT_ERROR OR UTL_SMTP.PERMANENT_ERROR THEN
UTL_SMTP.QUIT(v_MAIL_CONN);
RAISE_APPLICATION_ERROR (
-20000,
'Failed to send mail due to the following error: ' ||
sqlerrm
);
WHEN OTHERS THEN
RAISE_APPLICATION_ERROR (
-20001,
'The following error has occured: ' || sqlerrm
);
END;
/
-- show errors
SELECT
LINE,
POSITION,
TEXT
FROM
DBA_ERRORS
WHERE
NAME='SEND_MAIL'
ORDER BY
LINE,
POSITION
;
GRANT EXECUTE ON SEND_MAIL TO PUBLIC
;
CREATE OR REPLACE PUBLIC SYNONYM SENDMAIL FOR SEND_MAIL
;
/* Now test it */
SET SERVEROUTPUT ON SIZE 100000
EXEC SEND_MAIL ( -
p_to => '&your_email_address', -
p_subject => 'test subject', -
p_message => 'test message' -
);
EXEC SEND_MAIL ( -
p_to => '&your_email_address', -
p_cc => '&your_friends_email_address', -
p_subject => 'test subject', -
p_message => 'test message' -
);
The information transmitted is intended only for the person or entity to
which it is addressed and may contain confidential and/or privileged
material. If the reader of this message is not the intended recipient,
you are hereby notified that your access is unauthorized, and any review,
dissemination, distribution or copying of this message including any
attachments is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete the material from any
computer.
--------
website: http://www.LazyDBA.com
Please don't reply to RTFM questions
Oracle documentation is here: http://tahiti.oracle.com
To unsubscribe: see http://www.lazydba.com/unsubscribe.html
To subscribe: see http://www.lazydba.com
By using this list you agree to these terms:http://www.lazydba.com/legal.html
Oracle LazyDBA home page