UTL_SMTP.vrfy()
I have written a procedure that uses UTL_SMTP to send the emails. I want to verify the recipient address and am using the verfy() as below:
v_destination :=utl_smtp.vrfy(mail_conn, recipient);
I have given v_destination as VARCHAR2(500).
It shows errors "statement ignored, wrong expression".
Does anybody know how to use this function or is there an alternative way to check the status of emails?
Thanks
Amit
null
when you execute the program it would error out if the sender\recipient address is not available in the server.
Regards,
Bhagat
Similar Messages
-
Hw to use vrfy function in UTL SMTP
hw to use function below--
FUNCTION vrfy(c IN OUT NOCOPY connection,
recipient IN VARCHAR2) RETURN reply;
i want to check if senders address i m sending is right or not means exists on server or not
sample code---
declare
vs_errordesc varchar2(4000);
vs_conn UTL_SMTP.connection;
reply varchar2(1000);
begin
vs_conn := UTL_SMTP.open_connection (xyz.com',25);
UTL_SMTP.helo (vs_conn,'xyz.com');
UTL_SMTP.VRFY (vs_conn,'[email protected]') ;
dbms_output.put_line (reply);
exception when others then
vs_errordesc :=sqlerrm;
dbms_output.put_line (vs_errordesc);
end;
i want to check whts reply hw can i check it?
i m getting error here
--UTL_SMTP.VRFY (vs_conn,'[email protected]') ;
can u anyone helpThe VRFY command is basically useless.. had a good intent, but no practical way to do it accurately and correctly, nor does it serve any real purpose.
Some servers (especially older SMTP version) will simply parse the e-mail address and check if the format is correct. E.g.
-> VRFY [email protected]
<- 252 <[email protected]>
Newer servers will return a 502, meaning that the command is not implemented. E.g.
-> VRFY [email protected]
<- 502 smtp.domain.com: Command not implemente
The reason for this is that in the vast majority of times, the SMTP server you are talking to does not own the address of the recipient. You usually send e-mail to someone in another domain, via your domain's SMTP server.
How can your domain's SMTP server verify the recipient's address when it belongs to another domain? And what can it check? The domain name? How and why? It is not as simple as it sound.
When you deliver an e-mail to recipient on the same domain, the VRFY also does not make sense. Why waste a round trip on that command? If VRFY says okay, you still need to send the address via the RCPT TO command. So simply send a RCPT TO command and have the server telling you yea or nae - a single round trip dealing with the recipient's address. -
How to use CC and BCC in demo mail
how to use CC and BCC in the demo mail ?
I havent tried bcc. But I tried cc. Below is the code. It works excellent+
PROCEDURE RAJ_MAILCC (
from_addrs VARCHAR2,
to_addrs VARCHAR2,
cc_addrs VARCHAR2,
sub VARCHAR2,body IN VARCHAR2) IS
conn UTL_SMTP.CONNECTION;
crlf VARCHAR2( 2 ):= CHR( 13 ) || CHR( 10 );
vrfy_msg utl_smtp.reply;
SUCCESS_VALUE NUMBER(4) := 252;
oracle_sid varchar2(20);
email_addr varchar2(50):= null;
from_addr varchar2(100) := '<<from email id >>';
to_addr varchar2(1000):= to_addrs;
cc_addr varchar2(1000):= cc_addrs;
mesg VARCHAR2(4000);
subject varchar2(300):= sub;
mail_body varchar2(32000) := body;
to_mail varchar2(1000) := null;
cc_mail varchar2(1000) := null;
no_addresses number(4):= 0;
temp varchar2(4000) := null;
temp2 varchar2(4000) := null;
ERROR_ADDR varchar2(20):= '<<to email id for errors>>';
ERROR_MSG varchar2(1000);
ERROR_SUBJECT varchar2(1000) := 'Error in email '|| sub;
begin
mail_body := 'To:'||to_addrs || chr(10) ||'CC:'|| cc_addrs || chr(10) ||'Sub:'|| sub || chr(10) || body;
subject := 'Test: ' || sub;
select email, cc_email
into to_addr, cc_addr
from my_table
where userid = user;
temp := to_addrs||';';
while( instr( temp, ';') != 0) LOOP
temp := substr(temp, instr( temp, ';') + 1);
temp2 :=to_addr||';'|| temp2;
end loop;
to_addr := temp2;
temp := cc_addrs||';';
temp2 := null;
while( instr( temp, ';') != 0) LOOP
temp := substr(temp, instr( temp, ';') + 1);
temp2 :=cc_addr||';'|| temp2;
end loop;
cc_addr := temp2;
end if;
/*** Establish a connection to a mail server******/
conn:= utl_smtp.open_connection( 'MAIL SERVER', 25 );
utl_smtp.helo( conn, 'MAIL SERVER' );
utl_smtp.mail( conn, from_addr );
to_addr := to_addr || ';';
cc_addr := cc_addr || ';';
to_mail := to_addr;
cc_mail := cc_addr;
/*** Send mail to To: addresses ****/
while( instr( to_addr, ';') != 0) LOOP
email_addr := substr( to_addr, 1, instr( to_addr, ';') - 1);
vrfy_msg := utl_smtp.vrfy(conn,email_addr);
IF vrfy_msg.code = SUCCESS_VALUE THEN
UTL_SMTP.RCPT( conn,email_addr );
END IF;
to_addr := substr(to_addr, instr( to_addr, ';') + 1);
email_addr := null;
end loop;
/*** Send mail to CC: addresses ****/
while( instr( cc_addr, ';') != 0) LOOP
email_addr := substr( cc_addr, 1, instr( cc_addr, ';') - 1);
vrfy_msg := utl_smtp.vrfy(conn,email_addr);
IF vrfy_msg.code = SUCCESS_VALUE THEN
UTL_SMTP.RCPT( conn, email_addr);
END IF;
cc_addr := substr(cc_addr, instr( cc_addr, ';') + 1);
email_addr := null;
end loop;
mesg:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
'From: ' || 'Abacus' || ' <' || from_addr || '>' || crlf ||
'To: '|| to_mail || crlf ||
'Cc : '|| cc_mail || crlf ||' ' || crlf ||
'Subject: ' || subject || crlf;
mesg:= mesg || '' || crlf || mail_body;
utl_smtp.data( conn, mesg );
utl_smtp.quit( conn );
EXCEPTION
WHEN OTHERS THEN
ERROR_MSG := 'Mail notification could not be sent '||SQLERRM;
sendmailcc(ERROR_ADDR, ERROR_ADDR, null, ERROR_SUBJECT, ERROR_MSG); /
RAISE_APPLICATION_ERROR(-20001,ERROR_MSG);
END; -
Validating a user at a domain (email account) in PL/SQL
I have seen code in .NET that can validate an email account and I attempted to port this over to oracle and could not get it to work. I do understand that oracle 10G has a function utl_inaddr.get_host_address that can be used to validate a domain; however, I would like to validate a user at a domain (email account).
my code I am using is:
DECLARE
conn utl_smtp.connection;
rply utl_smtp.reply;
smtp_error EXCEPTION;
mail_conn utl_tcp.connection;
BEGIN
-- open SMTP connection
conn := utl_smtp.open_connection(smtp_host, smtp_port);
rply := utl_smtp.helo(conn, smtp_domain);
DBMS_OUTPUT.PUT_LINE ('Helo Response:'||rply.code||'/'||rply.text);
rply := utl_smtp.vrfy(conn, my_recipients);
DBMS_OUTPUT.PUT_LINE ('vrfy Response:'||rply.code||'/'||rply.text);
rply := utl_smtp.quit(conn);
DBMS_OUTPUT.PUT_LINE ('quit Response:'||rply.code||'/'||rply.text);
END;
The output I get is:
Helo Response:250/OK
vrfy Response:252/Cannot verify user
quit Response:221/closing connection
Can anyone assist me in getting this to work?
ThanksI'm afraid I can't help with that. I assume it's something in the configuration/setup/capabilities of the SMTP server, but I don't know the specifics. What are you using? Is there an admin you can request help from?
-
Hi,
I want to create a simple mail form using portal. The form must not use the HTML "mailto:", cause this requires a mail client to be installed at the customers computer. So I want to use the UTL_SMTP package. I managed to send mails with this package, but the problem is: how do I build my form with lets say 3 fields, so that i can pass the entered values to the SendMail-Funtion? I tried to create a form based on a table, then add new items and delete the table-based-items, but that doesnt work. I cant access the not table-based-items and found the reasons for that in the forums here. Then I tried to do it with a dynamic page, but I didnt succeed in calling my send-mail-function from the dynamic page. How can I do it?
Bye,
Pascal
nullPascal,
You can use something like this:
Create two tables:
1) Table1
(id NUMBER PRIMARY KEY, sender varchar2(100),
recipient varchar2(100) ,message varchar2(3000) ,subject varchar2(200))
2) Table2
(id NUMBER , sender varchar2(100),
recipient varchar2(100) ,message varchar2(3000) ,subject varchar2(200))
Here Table2 & Table1 are identical. You can use only one table if you do not want to maintain the history of the mails sent.
Base your form on "Table1".
Now pass whatever values you want to pass you can base it through this form to the table1(I mean INSERT).
Calling utl_smtp directly from here won't be a good idea because your form will hang unless the mail is sent.
So create a procedure for sending mails:
it should be something like this:
create or replace procedure send_email (sender IN varchar2, recipient IN varchar2,
message IN varchar2, subject IN varchar2)
is
mailhost varchar2(30) := 'your mail host';
mail_conn utl_smtp.connection;
Vhelo utl_smtp.reply;
Vvrfy utl_smtp.reply;
Vmail utl_smtp.reply;
Vrcpt utl_smtp.reply;
Vdata utl_smtp.reply;
Vquit utl_smtp.reply;
Vtemp number;
VMsg varchar2(4000);
begin
VMsg := 'Subject:'| |subject| |chr(10)| |message;
mail_conn := utl_smtp.open_connection(mailhost,25);
Vhelo := utl_smtp.helo(mail_conn, mailhost);
Vvrfy := utl_smtp.vrfy(mail_conn, recipient);
Vmail := utl_smtp.mail(mail_conn, sender);
Vrcpt := utl_smtp.rcpt(mail_conn, recipient);
vdata := utl_smtp.data(mail_conn, VMsg);
Vquit := utl_smtp.quit(mail_conn);
-- Handle the error
end;
create or replace procedure call_send_email
cursor Cur1 is
select * from table1;
is
for vcur1 in cur1
loop
send_email(vcur1.sender, cur1.recipient, vcur1.message, vcur1.subject);
insert into table2 values(vcur1.id,vcur1.sender, vcur.recipient,
vcur1.message, vcur1.subject);
delete from table1 where id = vcur1.id;
End Loop;
commit;
exception
--handle exception
end;
now call this procedure (call_send_mail) from dbms_job
Hope this helps,
Chetan. -
UTL_SMTP External Email
I can send internal emails successfully using the package UTL_SMTP, but as we have a separate security policy for external emails I have not been able to send emails outside the organisation.
In both cases the emails are being sent from an e-mail address that has privileges to send external emails utl_smtp.mail( conn, '[email protected]' );
I presume this isn't working because emails sent from Oracle aren't using the Exchange server account for '[email protected]' (I can send emails from [email protected] so this is definitely the case).
My question is, when I send an e-mail from Oracle, even through the utl_smtp.mail is set to a user defined e-mail address, which is the actual e-mail account it is being sent from? (eg: [email protected]) I can then change the privileges for this account on our Exchange server.
Thanks in advance.
Jayesh KaviaOur Novell email server rejects senders that are not in the address book, so I guess you'd have to look at the Exchange configuration. You could try using the VRFY command if it is implemented. RFC 2821 (which superceeds RFC 821, and is available from http://www.faqs.org/rfcs/ and many other sources) explains the guts of SMTP.
-
UTL_SMTP Send E-Mail Externally
I need to to send emails external to our organisational domain using UTL_SMTP. UTL_SMTP allows the sender to be set to anything you want (eg: [email protected]). I want to authenticate limit the sender to those people who have an account on our MS Exchange Server.
Is there anyway I can use UTL_SMTP to authenticate to an Exchange server account before sending an email.
Thanks,
Jay
I have not been able to send emails outside the organisation.
In both cases the emails are being sent from an e-mail address that has privileges to send external emails utl_smtp.mail( conn, '[email protected]' );
I presume this isn't working because emails sent from Oracle aren't using the Exchange server account for '[email protected]' (I can send emails from so this is definitely the case).
My question is, when I send an e-mail from Oracle, even through the utl_smtp.mail is set to a user defined e-mail address, which is the actual e-mail account it is being sent from? (eg: [email protected]) I can then change the privileges for this account on our Exchange server.
Thanks in advance.
Jayesh KaviaOur Novell email server rejects senders that are not in the address book, so I guess you'd have to look at the Exchange configuration. You could try using the VRFY command if it is implemented. RFC 2821 (which superceeds RFC 821, and is available from http://www.faqs.org/rfcs/ and many other sources) explains the guts of SMTP.
-
Sending email to multiple address using Utl_Smtp
Hi,
I want to send email to multiple address using the Utl_Smtp feature.
When I am sending email to one email address in the To:Field it works fine.However, when I send
to multiple address I am getting the below error.I am using a table(Email_test) to store all email id.
Error report:
ORA-29279: SMTP permanent error: 501 5.1.3 Invalid address
ORA-06512: at "SYS.UTL_SMTP", line 20
ORA-06512: at "SYS.UTL_SMTP", line 98
ORA-06512: at "SYS.UTL_SMTP", line 240
ORA-06512: at line 48
29279. 00000 - "SMTP permanent error: %s"
*Cause: A SMTP permanent error occurred.
*Action: Correct the error and retry the SMTP operation.
I am trying two options both ways I am getting error
Option 1:
Selecting two email id indivually in the select query as below
select email into v_Recipient1 from Email_test where Key_name='U1';
select email into v_Recipient2 from Email_test where Key_name='U2';
v_Recipient := v_Recipient1||';'||v_Recipient2;
Option 2:
Is there a way to use option
select email into v_Recipient1 from Email_test where Key_name='U4';
===========================================================
Create table Script
===========================================================
create table Email_test (Email varchar2(100),Key_name varchar2(10));
insert into Email_test values ('[email protected]','U1');
insert into Email_test values ('[email protected]','U2');
insert into Email_test values ('[email protected]','U3')
insert into Email_test values ('[email protected];[email protected];[email protected]','U4');
select * from Email_test
[email protected] U1
[email protected] U2
[email protected] U3
[email protected];[email protected];[email protected] U4
select * from Email_test where Key_name in ('U1','U2','U3')
[email protected] U1
[email protected] U2
[email protected] U3
select * from Email_test where Key_name='U4'
[email protected];[email protected];[email protected]
=======================================================
PL/SQL Block
===========================================================
declare
v_From VARCHAR2(80) := '[email protected]';
v_cc VARCHAR2(80);
v_Recipient VARCHAR2(80) ;
v_Recipient1 VARCHAR2(80) ;
v_Recipient2 VARCHAR2(80) ;
v_Subject VARCHAR2(80);
v_Mail_Host VARCHAR2(50);
v_Mail_Conn utl_smtp.Connection;
crlf VARCHAR2(2) := chr(13)||chr(10);
begin
--Mail Host name
select VALUE into v_Mail_Host from Server_info where server_name = 'SMTPServer';
select email into v_Recipient1 from Email_test where Key_name='U1';
select email into v_Recipient2 from Email_test where Key_name='U2';
v_Recipient := v_Recipient1||';'||v_Recipient2;
--for CC
select email into v_cc from Email_test where Key_name='U3';
v_Mail_Conn := utl_smtp.Open_Connection(v_Mail_Host, 25);
utl_smtp.Helo(v_Mail_Conn, v_Mail_Host);
utl_smtp.Mail(v_Mail_Conn, v_From);
utl_smtp.Rcpt(v_Mail_Conn, v_Recipient);
utl_smtp.Rcpt(v_Mail_Conn, v_cc); -- To CC recepient
utl_smtp.Rcpt(v_Mail_Conn, v_BCC); To BCC recepient
utl_smtp.Data(v_Mail_Conn,
'Date: ' || to_char(sysdate, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf ||
'From: ' || v_From || crlf ||
'Subject: '|| v_Subject || crlf ||
'To: ' || v_Recipient || crlf ||
'Cc: ' || v_cc || crlf ||
'Content-Type: text/html;' ||crlf ||
--'Hello this is a test email');
crlf || to_char(sysdate, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf );
utl_smtp.Quit(v_mail_conn);
end;
Any suggestion how to approach this issue.
Thank youSimple Mail Transfer Protocol RFC 5321 specifications.
RCPT TO:<forward-path> [ SP <rcpt-parameters> ] <CRLF>
The first or only argument to this command includes a forward-path
(normally a mailbox and domain, always surrounded by ">" and "<"
brackets) identifying one recipient.In other words, you can only define a SINGLE mailbox address at a time. Multiple addresses requires multiple repeats of this command verb, once per maibox.
Do not confuse this and the To: tag line in the Mime header that contains a comma delimited list of recipients. That tag line can contain anything - it is not parsed, not checked, and not verified as matching the actual recipient mailboxes as specified via the RCPT TO verb. -
Sending email using UTL_SMTP
Dear experts,
I am trying to send an email using UTL_SMTP (i switched from UTL_MAIL to UTL_SMTP since i need to send mails with large attachments - BLOB). I am using the demo_mail package given here:
http://www.oracle.com/technology/sample_code/tech/pl_sql/htdocs/Utl_Smtp_Sample.html
While running the program I am getting an error message (from the error.log) saying:
[Mon Aug 04 14:00:21 2008] [error] [client 192.168.0.7] mod_plsql: /ns/email_p.send HTTP-404 ORA-29279: SMTP permanent error: 530 5.7.0 Must issue a STARTTLS command first. 9sm12723808qbw.6\nORA-06512: at "SYS.UTL_SMTP", line 20\nORA-06512: at "SYS.UTL_SMTP", line 98\nORA-06512: at "SYS.UTL_SMTP", line 221\nORA-06512: at "NEXTSTEP.SEND_EMAIL_HELPER", line 258\nORA-06512: at "NEXTSTEP.SEND_EMAIL_HELPER", line 119\nORA-06512: at "NEXTSTEP.EMAIL_P", line 33\nORA-06512: at line 31\n, referer: file:///C:/Documents and Settings/Mayank/My Documents/Flex Builder 3/ns5/bin-debug/main.swf
My code is as follows:
PACKAGE DECLARATION. This is the DEMO_MAIL package posted under above link (I have renamed it).
CREATE OR REPLACE PACKAGE NEXTSTEP.send_email_helper IS
----------------------- Customizable Section -----------------------
-- Customize the SMTP host, port and your domain name below.
smtp_host VARCHAR2(256) := 'smtp.gmail.com';
smtp_port PLS_INTEGER := 587;
smtp_domain VARCHAR2(256) := null;
-- Customize the signature that will appear in the email's MIME header.
-- Useful for versioning.
MAILER_ID CONSTANT VARCHAR2(256) := 'Mailer by Oracle UTL_SMTP';
--------------------- End Customizable Section ---------------------
-- A unique string that demarcates boundaries of parts in a multi-part email
-- The string should not appear inside the body of any part of the email.
-- Customize this if needed or generate this randomly dynamically.
BOUNDARY CONSTANT VARCHAR2(256) := '-----7D81B75CCC90D2974F7A1CBD';
FIRST_BOUNDARY CONSTANT VARCHAR2(256) := '--' || BOUNDARY || utl_tcp.CRLF;
LAST_BOUNDARY CONSTANT VARCHAR2(256) := '--' || BOUNDARY || '--' ||
utl_tcp.CRLF;
-- A MIME type that denotes multi-part email (MIME) messages.
MULTIPART_MIME_TYPE CONSTANT VARCHAR2(256) := 'multipart/mixed; boundary="'||
BOUNDARY || '"';
MAX_BASE64_LINE_WIDTH CONSTANT PLS_INTEGER := 76 / 4 * 3;
-- A simple email API for sending email in plain text in a single call.
-- The format of an email address is one of these:
-- someone@some-domain
-- "Someone at some domain" <someone@some-domain>
-- Someone at some domain <someone@some-domain>
-- The recipients is a list of email addresses separated by
-- either a "," or a ";"
PROCEDURE mail(sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
message IN VARCHAR2);
-- Extended email API to send email in HTML or plain text with no size limit.
-- First, begin the email by begin_mail(). Then, call write_text() repeatedly
-- to send email in ASCII piece-by-piece. Or, call write_mb_text() to send
-- email in non-ASCII or multi-byte character set. End the email with
-- end_mail().
FUNCTION begin_mail(sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
priority IN PLS_INTEGER DEFAULT NULL)
RETURN utl_smtp.connection;
-- Write email body in ASCII
PROCEDURE write_text(conn IN OUT NOCOPY utl_smtp.connection,
message IN VARCHAR2);
-- Write email body in non-ASCII (including multi-byte). The email body
-- will be sent in the database character set.
PROCEDURE write_mb_text(conn IN OUT NOCOPY utl_smtp.connection,
message IN VARCHAR2);
-- Write email body in binary
PROCEDURE write_raw(conn IN OUT NOCOPY utl_smtp.connection,
message IN RAW);
-- APIs to send email with attachments. Attachments are sent by sending
-- emails in "multipart/mixed" MIME format. Specify that MIME format when
-- beginning an email with begin_mail().
-- Send a single text attachment.
PROCEDURE attach_text(conn IN OUT NOCOPY utl_smtp.connection,
data IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
last IN BOOLEAN DEFAULT FALSE);
-- Send a binary attachment. The attachment will be encoded in Base-64
-- encoding format.
PROCEDURE attach_base64(conn IN OUT NOCOPY utl_smtp.connection,
data IN RAW,
mime_type IN VARCHAR2 DEFAULT 'application/octet',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
last IN BOOLEAN DEFAULT FALSE);
-- Send an attachment with no size limit. First, begin the attachment
-- with begin_attachment(). Then, call write_text repeatedly to send
-- the attachment piece-by-piece. If the attachment is text-based but
-- in non-ASCII or multi-byte character set, use write_mb_text() instead.
-- To send binary attachment, the binary content should first be
-- encoded in Base-64 encoding format using the demo package for 8i,
-- or the native one in 9i. End the attachment with end_attachment.
PROCEDURE begin_attachment(conn IN OUT NOCOPY utl_smtp.connection,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
inline IN BOOLEAN DEFAULT TRUE,
filename IN VARCHAR2 DEFAULT NULL,
transfer_enc IN VARCHAR2 DEFAULT NULL);
-- End the attachment.
PROCEDURE end_attachment(conn IN OUT NOCOPY utl_smtp.connection,
last IN BOOLEAN DEFAULT FALSE);
-- End the email.
PROCEDURE end_mail(conn IN OUT NOCOPY utl_smtp.connection);
-- Extended email API to send multiple emails in a session for better
-- performance. First, begin an email session with begin_session.
-- Then, begin each email with a session by calling begin_mail_in_session
-- instead of begin_mail. End the email with end_mail_in_session instead
-- of end_mail. End the email session by end_session.
FUNCTION begin_session RETURN utl_smtp.connection;
-- Begin an email in a session.
PROCEDURE begin_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection,
sender IN VARCHAR2,
recipients IN VARCHAR2,
subject IN VARCHAR2,
mime_type IN VARCHAR2 DEFAULT 'text/plain',
priority IN PLS_INTEGER DEFAULT NULL);
-- End an email in a session.
PROCEDURE end_mail_in_session(conn IN OUT NOCOPY utl_smtp.connection);
-- End an email session.
PROCEDURE end_session(conn IN OUT NOCOPY utl_smtp.connection);
END;How should I solve the above error? Can anyone help me with my query please?
If I add the code to start TLS it still gives me an error. If I add the code
utl_smtp.command(conn,'STARTTLS');
utl_smtp.helo(conn, smtp_domain);
under email_sender_help package just before under begin_session function, it gives me an error saying:
ORA-29279: SMTP permanent error: 503 5.5.1 EHLO/HELO first. s27sm2097329qbs.12
So then if i enter the same code after:
utl_smtp.command(conn,'STARTTLS');
utl_smtp.helo(conn, smtp_domain);
It gives me an error:
ORA-29278: SMTP transient error: 421 Service not available
Message was edited by:
Monk
Message was edited by:
Monklook like rely turned off on the server..
check this.. or ask your network guys..
Go to Control Panel->Add or Remove Programs->Click on
Add/Remove Wndows Components
Check IIS check box.
Select Internet Information Service (IIS) option and click on Details button
Check whether SMTP Service is checked or not.
If not selected then select SMTP check box.
This process should be done on server.
It will help out from ORA-29278: SMTP transient error: 421 Service not available problem.
thanks -
How to send email attachments in any format by utl_smtp?
Hi,
I am Using this Script for Sending Mail With an Attachment,i run this Script(Oracle 11g Database R1) and i got this Message "PL/SQL procedure successfully completed." but still i have not received the mail.
Please advice me....
set serveroutput on
/* Formatted on 2010/06/03 21:26 (Formatter Plus v4.8.8) */
DECLARE
v_file_handle UTL_FILE.file_type;
v_email_server VARCHAR2 (100) := 'Email_Server;
v_conn UTL_SMTP.connection;
v_port NUMBER := 25;
v_reply UTL_SMTP.reply;
v_msg VARCHAR2 (32767);
v_line VARCHAR2 (1000);
v_message VARCHAR2 (1000);
b_connected BOOLEAN := FALSE;
v_sender VARCHAR2 (50) := '************';
v_strt_day varchar2(100);
v_end_day varchar2(100);
crlf VARCHAR2 (2) := CHR (13) || CHR (10);
recpt VARCHAR2 (255) := '*********';
slp PLS_INTEGER := 300;
pdirpath VARCHAR2 (50) := 'D:\Mail_Process';
pfilename VARCHAR2 (50) := 'Multifile.html';
p_stat number := 0;
BEGIN
/***** Check if the file exists ****/
BEGIN
v_file_handle := UTL_FILE.fopen (pdirpath, pfilename, 'R');
EXCEPTION
WHEN UTL_FILE.invalid_path
THEN
p_stat := 99;
RETURN;
WHEN OTHERS
THEN
p_stat := 99;
RETURN;
END;
/***** Try to connect for three times, do sleep in between for 5minutes *****/
FOR i IN 1 .. 3
LOOP
BEGIN
--open the connection with the smtp server and do the handshake
v_conn := UTL_SMTP.open_connection (v_email_server, v_port);
v_reply := UTL_SMTP.helo (v_conn, v_email_server);
IF 250 = v_reply.code
THEN
b_connected := TRUE;
EXIT;
END IF;
EXCEPTION
WHEN OTHERS
THEN
DBMS_LOCK.sleep (slp);
END;
END LOOP;
IF b_connected = FALSE
THEN
p_stat := 99;
RETURN;
END IF;
v_reply := UTL_SMTP.mail (v_conn, v_sender);
IF 250 != v_reply.code
THEN
p_stat := 99;
RETURN;
END IF;
v_reply := UTL_SMTP.rcpt (v_conn, recpt);
IF 250 != v_reply.code
THEN
p_stat := 99;
RETURN;
END IF;
UTL_SMTP.open_data (v_conn);
v_message :=
'Sample Email This is an auto generated mail.
Please do not reply to this mail.'
|| CHR (10);
v_msg :=
'Date: '
|| TO_CHAR (SYSDATE, 'Mon DD yy hh24:mi:ss')
|| crlf
|| 'From: '
|| v_sender
|| crlf
|| 'Subject: '
|| 'Sample file'
|| crlf
|| 'To: '
|| recpt
|| crlf
|| 'Mime-Version: 1.0'
|| crlf
|| 'Content-Type: multipart/mixed;
boundary="DMW.Boundary.605592468"'
|| crlf
|| ''
|| crlf
|| v_message
|| crlf
|| ''
|| crlf
|| '--DMW.Boundary.605592468'
|| crlf
|| 'Content-Type: text/plain;
name="v_message.txt"; charset=US-ASCII'
|| crlf
|| 'Content-Disposition: inline; filename="v_message.txt"'
|| crlf
|| 'Content-Transfer-Encoding: 7bit'
|| crlf
|| ''
|| crlf
|| v_message
|| crlf
|| crlf
|| crlf;
UTL_SMTP.write_data (v_conn, v_msg);
/***** Prepare the attachment to be sent *****/
v_msg :=
crlf
|| '--DMW.Boundary.605592468'
|| crlf
|| 'Content-Type:
application/octet-stream; name="'
|| pfilename
|| '"'
|| crlf
|| 'Content-Disposition: attachment; filename="'
|| pfilename
|| '"'
|| crlf
|| 'Content-Transfer-Encoding: 7bit'
|| crlf
|| crlf;
UTL_SMTP.write_data (v_conn, v_msg);
LOOP
BEGIN
UTL_FILE.get_line (v_file_handle, v_line);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
EXIT;
END;
v_msg := '*** truncated ***' || crlf;
v_msg := v_line || crlf;
UTL_SMTP.write_data (v_conn, v_msg);
END LOOP;
UTL_FILE.fclose (v_file_handle);
v_msg := crlf;
UTL_SMTP.write_data (v_conn, v_msg);
v_msg := crlf || '--DMW.Boundary.605592468--' || crlf;
UTL_SMTP.write_data (v_conn, v_msg);
UTL_SMTP.close_data (v_conn);
UTL_SMTP.quit (v_conn);
EXCEPTION
WHEN OTHERS
THEN
p_stat := 99;
END;
Thank You
ShanI would recommend not to use home grown email solutions and use what we all use
1. UTL_MAIL oracle package http://download-west.oracle.com/docs/cd/B13789_01/appdev.101/b10802/u_mail.htm
or
2. SMTP rock solid solution http://www.oracle.com/technology/sample_code/tech/pl_sql/htdocs/maildemo_sql.txt -
Problem with utl_smtp.write_data - immediate help needed
Hi,
I have a sql code that generates a .csv file and sends it as an attachment through utl_smtp.
Everything works fine but the .csv file's header gets broken after certain characters..wondering why this is happening..pls help.
Please find my code below:
SET define off;
DECLARE
--CURSOR VARIABLES
v_meter_count NUMBER := 0;
v_meter_max_count NUMBER := 0;
v_sysdate DATE := TRUNC (SYSDATE);
--MAIL VARIABLES
v_run_date DATE := TRUNC (SYSDATE);
crlf CONSTANT VARCHAR2 (10) := UTL_TCP.crlf;
boundary CONSTANT VARCHAR2 (256)
:= '-----7D81B75CCC90D2974F7A1CBD';
first_boundary CONSTANT VARCHAR2 (256) := '--' || boundary || crlf;
last_boundary CONSTANT VARCHAR2 (256)
:= '--' || boundary || '--' || crlf;
multipart_mime_type CONSTANT VARCHAR2 (256)
:= 'multipart/mixed; boundary="' || boundary || '"';
conn UTL_SMTP.connection;
from_name VARCHAR2 (255) := 'Nielsen Online';
from_address VARCHAR2 (255)
:= '[email protected]';
to_address VARCHAR2 (255)
:= '[email protected]';
subject VARCHAR2 (255) := '';
mime_type VARCHAR2 (255) := 'text/plain';
attachment_file_name VARCHAR2 (255) := NULL;
mailhost VARCHAR2 (255) := '127.0.0.1';
--PANELISTS' DETAILS CURSOR
CURSOR tam_panelists
IS
SELECT a.panel_sys_id, a.panel_site_id, a.login_id,
b.recruit_start_date, c.meter_id, d.affiliate_id,
d.afflt_member_id,
(CASE
WHEN b.last_active_date >= TRUNC (SYSDATE) - 30
THEN 'Active'
ELSE 'Inactive'
END
) hh_status,
(SELECT e.affiliate_description
FROM pfshared3.lkp_affiliates e
WHERE e.partner_id =
NVL (d.affiliate_id, 0)
AND e.pnl_sys_id = a.panel_sys_id) affiliate_description
FROM mgtw.dat_ps_login_info a,
mgtw.dat_ps_install_info b,
mgtw.dat_ps_info c,
mgtw.dat_ps_recruit_info d
WHERE a.login_id LIKE 'tam%@tam%.com'
AND a.panel_site_id = b.panel_site_id
AND a.panel_sys_id = b.panel_sys_id
AND a.panel_site_id = c.panel_site_id
AND a.panel_sys_id = c.panel_sys_id
AND a.panel_site_id = d.panel_site_id
AND a.panel_sys_id = d.panel_sys_id
AND a.active_flag = 1
AND b.first_mtr_install_date IS NOT NULL
AND b.last_active_date IS NOT NULL;
--PANELISTS' PC DETAILS CURSOR
CURSOR pc_activity (p_meter_id IN VARCHAR2)
IS
SELECT cpt_guid, first_active_date, last_active_date,
TO_CHAR(first_install_date,'MM/DD/YYYY HH:MI') first_install_dt,
(TRUNC (SYSDATE) - last_active_date) inactive_days,
(CASE
WHEN last_active_date >= TRUNC (SYSDATE) - 30
THEN 'Active'
ELSE 'Inactive'
END
) status
FROM pfshared3.dat_pnl_computers
WHERE meter_id = p_meter_id
ORDER BY last_active_date DESC;
--RECORD TYPE FOR PANELISTS' DETAILS
TYPE t_panelist_set IS TABLE OF tam_panelists%ROWTYPE;
v_panelist_data t_panelist_set;
--RECORD TYPE FOR PANELISTS' PC DETAILS
TYPE t_pc_set IS TABLE OF pc_activity%ROWTYPE;
v_pc_data t_pc_set;
PROCEDURE send_header (NAME IN VARCHAR2, header IN VARCHAR2)
IS
BEGIN
UTL_SMTP.write_data (conn, NAME || ': ' || header || crlf);
END;
BEGIN
--MAX METER COUNT
BEGIN
SELECT MAX(COUNT (meter_id))
INTO v_meter_max_count
FROM pfshared3.dat_pnl_computers
WHERE last_active_date IS NOT NULL
GROUP BY meter_id;
EXCEPTION
WHEN OTHERS
THEN
v_meter_max_count := 0;
END;
DBMS_OUTPUT.put_line ( 'STARTED - '
|| TO_CHAR (SYSDATE, 'DD-MON-YYYY HH:MI:SS')
conn := UTL_SMTP.open_connection (mailhost);
UTL_SMTP.helo (conn, mailhost);
UTL_SMTP.mail (conn, '< ' || from_address || ' >');
UTL_SMTP.rcpt (conn, '< ' || to_address || ' >');
UTL_SMTP.open_data (conn);
send_header ('From', '"' || from_name || '" <' || from_address || '>');
send_header ('To', '' || to_address || '');
send_header ('Date', TO_CHAR (SYSDATE, 'dd Mon yy hh24:mi:ss'));
subject := 'TW Daily Activity Report' || ' - ' || v_run_date;
send_header ('Subject', subject);
send_header ('Content-Type', multipart_mime_type);
-- Close header section by a crlf on its own
UTL_SMTP.write_data (conn, crlf);
-- mime header
UTL_SMTP.write_data (conn, first_boundary);
send_header ('Content-Type', mime_type);
UTL_SMTP.write_data (conn, crlf);
UTL_SMTP.write_data (conn, crlf);
-- add the attachment
attachment_file_name := 'TW_Daily_Activity_Report_' || v_run_date || '.txt';
UTL_SMTP.write_data (conn, first_boundary);
send_header ('Content-Type', mime_type);
send_header ('Content-Disposition',
'attachment; filename= ' || attachment_file_name
UTL_SMTP.write_data (conn, crlf);
--CREATING HEADERS
UTL_SMTP.write_data (conn,
'Date of Reporting'
|| ','
|| 'Panelist ID'
|| ','
|| 'Meter ID'
|| ','
|| 'Panelist Email(Username)'
|| ','
|| 'Vendor'
|| ','
|| 'Affiliate ID'
|| ','
|| 'UID'
|| ','
|| 'Enrollment Date'
|| ','
|| 'HH Status'
|| ','
|| 'Registered PC in the HH'
|| ','
FOR k IN 1 .. v_meter_max_count
LOOP
UTL_SMTP.write_data (conn,
'Installation Date/Time MM/DD/YYYY HH:MI PC' || k || ',' || 'PC '|| k ||': Status' || ',' || 'PC '|| k ||': Date of First log' || ',' || 'PC '|| k ||': Date of Last log' || ',' || 'PC '|| k ||': Days since Last Activity' || ',' || 'PC '|| k ||': Computer ID' || ','
END LOOP;
UTL_SMTP.write_data (conn, crlf);
--OPENING PANELISTS' DETAILS CURSOR
OPEN tam_panelists;
--FETCHING PANELISTS' DETAILS CURSOR
FETCH tam_panelists
BULK COLLECT INTO v_panelist_data;
FOR i IN v_panelist_data.FIRST .. v_panelist_data.LAST
LOOP
--METER COUNT
BEGIN
SELECT COUNT (meter_id)
INTO v_meter_count
FROM pfshared3.dat_pnl_computers
WHERE meter_id = v_panelist_data (i).meter_id
GROUP BY meter_id;
EXCEPTION
WHEN OTHERS THEN
v_meter_count := 0;
END;
--OPENING PANELISTS' PC DETAILS CURSOR
OPEN pc_activity (v_panelist_data (i).meter_id);
--FETCHING PANELISTS' PC DETAILS CURSOR
FETCH pc_activity
BULK COLLECT INTO v_pc_data;
UTL_SMTP.write_data (conn,
v_sysdate
|| ','
|| v_panelist_data (i).panel_site_id
|| ','
|| v_panelist_data (i).meter_id
|| ','
|| v_panelist_data (i).login_id
|| ','
|| v_panelist_data (i).affiliate_description
|| ','
|| v_panelist_data (i).affiliate_id
|| ','
|| v_panelist_data (i).afflt_member_id
|| ','
|| v_panelist_data (i).recruit_start_date
|| ','
|| v_panelist_data (i).hh_status
|| ','
|| v_meter_count
|| ','
FOR j IN v_pc_data.FIRST .. v_pc_data.LAST
LOOP
UTL_SMTP.write_data (conn,
v_pc_data (j).first_install_dt
|| ','
|| v_pc_data (j).status
|| ','
|| v_pc_data (j).first_active_date
|| ','
|| v_pc_data (j).last_active_date
|| ','
|| v_pc_data (j).inactive_days
|| ','
|| v_pc_data (j).cpt_guid
|| ','
END LOOP;
UTL_SMTP.write_data (conn, crlf);
CLOSE pc_activity;
END LOOP;
CLOSE tam_panelists;
-- CLOSE THE MESSAGE
UTL_SMTP.write_data (conn, last_boundary);
-- CLOSE CONNECTION
UTL_SMTP.close_data (conn);
UTL_SMTP.quit (conn);
DBMS_OUTPUT.put_line ( 'ENDED - '
|| TO_CHAR (SYSDATE, 'DD-MON-YYYY HH:MI:SS')
RETURN;
EXCEPTION
WHEN UTL_SMTP.transient_error OR UTL_SMTP.permanent_error
THEN
UTL_SMTP.quit (conn);
raise_application_error
(-20000,
'Failed to send mail due to the following error: '
|| SQLERRM
WHEN OTHERS
THEN
raise_application_error
(-20000,
'Script failed due to the following error: '
|| SQLERRM
RETURN;
END;
Please find below the header of the .csv file generated:
Date of Reporting Panelist ID Meter ID Panelist Email(Username) Vendor Affiliate ID UID Enrollment Date HH Status Registered PC in the HH Installation Date/Time MM/DD/YYYY HH:MI PC1 PC 1: Status PC 1: Date of First log PC 1: Date of Last log PC 1: Days since Last Activity PC 1: Computer ID Installation Date/Time MM/DD/YYYY HH:MI PC2 PC 2: Status PC 2: Date of First log PC 2: Date of Last log PC 2: Days since Last Activity PC 2: Computer ID Installation Date/Time MM/DD/YYYY HH:MI PC3 PC 3: Status PC 3: Date of First log PC 3: Date of Last log PC 3: Days since Last Activity PC 3: Computer ID Installation Date/Time MM/DD/YYYY HH:MI PC4 PC 4: Status PC 4: Date of First log PC 4: Date of Last log PC 4: Days since Last Activity PC 4: Computer ID Installation Date/Time MM/DD/YYYY HH:MI PC5 PC 5: Status PC 5: Date of First log PC 5: Date of Last log PC 5: Days since Last Activity PC 5: Computer ID Installation Date/Time MM/DD/YYYY HH:MI PC6 PC 6: Status PC 6: Date of First log PC 6: Date of Last log PC 6: Days since Last Activity PC 6: Computer ID Installation Date/Time MM/DD/YYYY HH:MI PC7 PC 7: Status PC 7: Date of First log PC 7: Date of Last log PC 7: Days since Last Activity PC 7: Computer ID Installation Date/Time MM/DD/YYYY HH:MI PC8 PC 8: Status PC 8: Date of First log PC 8: Date of Last log PC 8: Days since Last Activity PC 8: Computer ID Installation Date/Time MM/DD/YYYY HH:MI PC9 PC 9: Status PC 9: Date of First log PC 9: Date of Last log PC 9: Days since Last Activity PC 9: Computer ID Installation Date/Time MM/DD/YYYY HH:MI PC10 PC 10: Status PC 10: Date of First log PC 10: Date of Last log PC 10: Days since Last Activity PC 10: Computer ID Installation Date/Time MM/DD/YYYY HH:MI PC11 PC 11: Status PC 11: Date of First log PC 11: Date of Last log PC 11: Days since Last Activity PC 11: Computer ID Installation Date/Time MM/DD/YYYY HH:MI PC12 PC 12: Status PC 12: Date of First log PC 12: Date of Last log PC 12: Days since Last Activity PC 12: Computer ID Installation Date/Time MM/DD/YYYY HH:MI PC13 PC!
*13: Sta *
tus PC 13: Date of First log PC 13: Date of Last log PC 13: Days since Last Activity PC 13: Computer ID
The one highlighted in bold is the broken header.
Please provide a solution to this.
Thanks
Monika
Edited by: 953348 on Aug 18, 2012 8:00 AMI can't provide a solution but maybe a little help. With the header line you posted here it seems to me that a new line starts after 2048 = 2^11 characters. This might be a limitation or a length of any variable in the package.
Maybe you can change this value or shorten the texts in the header to stay below this limit.
A few more things:
- the code, that you posted here became destroyed in lines like UTL_SMTP.mail (conn, '< ' .... because the forum software tried to find html-code between the "<" and ">" signs.
- you can mark code in your postings with (see FAQ). It makes code better readable but it does not help with the "<" and ">" signs.
- you left your e-mail-address in the header of the code. I guess this was not your intention. You can edit it and remove the address even after posting a message. -
Setting "Follow Up" flag in email thru utl_smtp
Hi,
Can anybody tell me, how can I set up "Follow up" flag with date in mail using utl_smtp.
Any help is greatly appreciated.Unless my recollection of RFC822, the "Follow Up" flag is not part of the SMTP protocol. So you'd have to ask the vendor of whatever front-end application your email recipients use how that particular application wants the follow up flag specified and whether the vendor extended the SMTP protocol to allow that.
Justin -
How to use UTL_SMTP to send email with existing file attachment
Hello! I am trying to create a pl/sql procedure that lets me send an email and include an existing file to a email address. So far, I found information on how to send a file and create an attachment with information I put in the procedure. This is NOT what I'm trying to do. I'm trying to send an email and include an attachment for a file that already exists. I need the pre-existing file to be sent to the email recipient.
This is how far I've gotten, but this only allows me to CREATE an attachment with the information I put in it from the procedure. I got it from the following site:
http://www.orafaq.com/wiki/Send_mail_from_PL/SQL
DECLARE
v_From VARCHAR2(80) := '[email protected]';
v_Recipient VARCHAR2(80) := '[email protected]';
v_Subject VARCHAR2(80) := 'Weekly Invoice Report';
v_Mail_Host VARCHAR2(30) := 'mail.mycompany.com';
v_Mail_Conn utl_smtp.Connection;
crlf VARCHAR2(2) := chr(13)||chr(10);
BEGIN
v_Mail_Conn := utl_smtp.Open_Connection(v_Mail_Host, 25);
utl_smtp.Helo(v_Mail_Conn, v_Mail_Host);
utl_smtp.Mail(v_Mail_Conn, v_From);
utl_smtp.Rcpt(v_Mail_Conn, v_Recipient);
utl_smtp.Data(v_Mail_Conn,
'Date: ' || to_char(sysdate, 'Dy, DD Mon YYYY hh24:mi:ss') || crlf ||
'From: ' || v_From || crlf ||
'Subject: '|| v_Subject || crlf ||
'To: ' || v_Recipient || crlf ||
'MIME-Version: 1.0'|| crlf || -- Use MIME mail standard
'Content-Type: multipart/mixed;'|| crlf ||
' boundary="-----SECBOUND"'|| crlf ||
crlf ||
'-------SECBOUND'|| crlf ||
'Content-Type: text/plain;'|| crlf ||
'Content-Transfer_Encoding: 7bit'|| crlf ||
crlf ||
'This is a test'|| crlf || -- Message body
'of the email attachment'|| crlf ||
crlf ||
'-------SECBOUND'|| crlf ||
'Content-Type: text/plain;'|| crlf ||
' name="ap_inv_supplier_cc10.txt"'|| crlf ||
'Content-Transfer_Encoding: 8bit'|| crlf ||
'Content-Disposition: attachment;'|| crlf ||
' filename="ap_inv_supplier_cc10.txt"'|| crlf ||
crlf ||
'TXT,file,attachment'|| crlf || -- Content of attachment (THIS IS MY PROBLEM! I NEED TO BE ABLE TO ATTACH AN EXISTING FILE, NOT CREATE A NEW ONE)
crlf ||
'-------SECBOUND--' -- End MIME mail
utl_smtp.Quit(v_mail_conn);
EXCEPTION
WHEN utl_smtp.Transient_Error OR utl_smtp.Permanent_Error then
raise_application_error(-20000, 'Unable to send mail: '||sqlerrm);
END;
/First, you must create a directory object
create directory ORALOAD as '/home/ldcgroup/ldccbc/'
/Study the Prerequisites in the link I posted above, or else you will not be able to read/write files from the above directory object
"fname" relates to the file name that you read from.
In the code below, it is also the name of the file that you are attaching.
Although they can be different!
l_Output is the contents of the file.
declare
vInHandle utl_file.file_type;
flen number;
bsize number;
ex boolean;
l_Output raw(32767);
fname varchar2(30) := 'ap_inv_supplier_cc10.txt';
vSender varchar2(30) := '[email protected]';
vRecip varchar2(30) := '[email protected]';
vSubj varchar2(50) := 'Weekly Invoice Report';
vAttach varchar2(50) := 'ap_inv_supplier_cc10.txt';
vMType varchar2(30) := 'text/plain; charset=us-ascii';
begin
utl_file.fgetattr('ORALOAD', fname, ex, flen, bsize);
vInHandle := utl_file.fopen('ORALOAD', fname, 'R');
utl_file.get_raw (vInHandle, l_Output);
utl_file.fclose(vInHandle);
utl_mail.send_attach_raw(sender => vSender
,recipients => vRecip
,subject => vsubj
,attachment => l_Output
,att_inline => false
,att_filename => fname);
end;
/ -
How to use alias in "From" field when I send a mail with utl_smtp ?
Hi all,
I'm using a PL/SQL package with an Oracle 11G database to send mails. It works fine but instead of use of my mail in "From" field like "[email protected]" as sender E-mail address, I would like to have "Toto" in the sender address. I tryied to use utl_smtp.mail(l_connection, '<toto> [email protected]') but it doesn't work. The only way I can send mail is when I set utl_smtp.mail(l_connection, '<[email protected]>') directly. When I use the Alias, I have an error from smtp server telling that I use a bad syntax address.
Does someone know how to use the alias ? Where do I do a mistake ?
Thank you for your help.
sis2bThank you, I find how to solve the problem thanks to your link.
I try to send HTML E-mail so I had the From in the from field writen in the header of the mail and not to initialize the connection.
sis2b. -
How can I email using UTL_SMTP with a csv file as an attachment?
Dear All,
It would be great if someone could help me. I am trying to use UTL_SMTP to email with a csv file as attachment. I do get an email with a message but no attachment arrives with it.
In fact the code used for attaching the csv file gets appended in the message body in the email.
CREATE OR REPLACE PROCEDURE test_mail
AS
SENDER constant VARCHAR2(80) := '[email protected]';
MAILHOST constant VARCHAR2(80) := 'mailhost.xxxx.ac.uk';
mail_conn utl_smtp.connection;
lv_rcpt VARCHAR2(80);
lv_mesg VARCHAR2(9900);
lv_subject VARCHAR2(80) := 'First Test Mail';
lv_brk VARCHAR2(2) := CHR(13)||CHR(10);
BEGIN
mail_conn := utl_smtp.open_connection(mailhost, 25) ;
utl_smtp.helo(mail_conn, MAILHOST) ;
dbms_output.put_line('Sending Email to : ' ||lv_brk||'Suhas Mitra' ) ;
lv_mesg := 'Date: '||TO_CHAR(sysdate,'dd Mon yy hh24:mi:ss')||lv_brk||
'From: <'||SENDER||'>'||lv_brk||
'Subject: '||lv_subject||lv_brk||
'To: '||'[email protected]'||lv_brk||
'MIME-Version: 1.0'||lv_brk||
'Content-type:text/html;charset=iso-8859-1'||lv_brk||
' boundary="-----SECBOUND"'||
''||lv_brk||
'-------SECBOUND'||
'Some Message'
|| lv_brk ||
'-------SECBOUND'||
'Content-Type: text/plain;'|| lv_brk ||
' name="xxxx.csv"'|| lv_brk ||
'Content-Transfer_Encoding: 8bit'|| lv_brk ||
'Content-Disposition: attachment;'|| lv_brk ||
' filename="xxxx.csv"'|| lv_brk ||
lv_brk ||
'CSV,file,attachement'|| lv_brk || -- Content of attachment
lv_brk||
'-------SECBOUND' ;
dbms_output.put_line('lv_mesg : ' || lv_mesg) ;
utl_smtp.mail(mail_conn, SENDER) ;
lv_rcpt := '[email protected]';
utl_smtp.rcpt(mail_conn, lv_rcpt) ;
utl_smtp.data(mail_conn, lv_mesg) ;
utl_smtp.quit(mail_conn);
EXCEPTION
WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
NULL ;
WHEN OTHERS THEN
dbms_output.put_line('Error Code : ' || SQLCODE) ;
dbms_output.put_line('Error Message : ' || SQLERRM) ;
utl_smtp.quit(mail_conn) ;
END;LKBrwn_DBA wrote:
Use UTL_MAIL instead.That package is an utter disappointment - and an excellent example IMO of how not to design an application programming interface. Even the source code is shoddy.. I mean, having to resort to a GOTO statement....!!?? The person(s) who wrote that package are sorely lacking in even the most basic of programming skills if structured programming is ignored and a spaghetti command used instead.
No wonder the public interface of that code is equally shabby and thoughtless... The mail demo code posted by Oracle was better written than this "+package+" they now have bundled as the official Mail API.
I dunno.. if I was in product management there would have been hell to pay over pushing cr@p like that to customers.
Maybe you are looking for
-
External Hard drive won't edit?
I have been PC for 15 years and just moved to a MAC to do graphic design on for college and future. Just set this up 2 nights ago. I bought a brand new 20inch 2GB 2.66ghz, 320GB hard drive. Now, I have just a plain ole'USB external hard drive with al
-
ActionScript 3.0 Lang/Comp ref help not downloading
The AS3 language and componet referance help will not download. The blue bar bounces back and forth from about 0 to 50 percent and will not finnish. i tried removing all the help files and re-installing them(including the help app itself), all of the
-
I want to attach a song to a text message is that possible
I want to send my wife the song all i want for christmas is you but I cannot figure out how is it possible
-
Call graphical calc view with parameters
Hello, We want to call a graphical calculation view that requires parameters via CE functions. Is this possible? How can we do that? Thanks, Oshrit.
-
Setting Current Date on a checkbox
Hi all, I have a requirement in which all the rows have a checkbox if user checks the checkbox and save the record I need to populated current date for checked record in a column. Please guide me in this regard. Its urgent please. Thanks Ragni Gupta