UTL_SMTP - Package
Ramesh Vadlamani, August 20, 2002 - 11:42 am UTC
Hi,
This review is so very good. I am just the beginner in Oracle and i am trying to send create a procedure which
will send a automated message from server to the me.
this helped me a lot. and thanks a lot for maintaing a
good website.
RAMS
UTL_SMTP
Ramesh Vadlamani, November 05, 2002 - 1:18 pm UTC
Dear Tom,
Thank for your detailed suggestions, actually i have posted my review about this UTL_SMTP before, but after i saw my own review i recognised that i missed so many words and letters in my typing,so i am doing this once again.
Anyway..s thanx for your suggestions.
Thanks
Ramesh.
But how do i verify if the recipent address is correct?
Rahul, July 20, 2004 - 9:13 am UTC
Hi Tom,
I have this problem. I have read about the vrfy function in the UTL_SMTP package . I would like to use the same but the oracle docs dont provide the necessary information on thins neither i have found a singe example on this site which uses it. Could you please give me a imple eample.
Thanks,
Rahul.
July 20, 2004 - 7:57 pm UTC
vrfy is just an SMTP instruction. if you telnet to your smtp server, you can see what it supports and see how to use it:
[tkyte@tkyte-pc-isdn tkyte]$ telnet aria.us.oracle.com 25
Trying 138.2.5.51...
Connected to aria.us.oracle.com.
Escape character is '^]'.
help
220 aria-lnx.us.oracle.com ESMTP Sendmail 8.11.6/8.11.6; Tue, 20 Jul 2004 19:53:35 -0400
214-2.0.0 This is sendmail version 8.11.6
214-2.0.0 Topics:
214-2.0.0 HELO EHLO MAIL RCPT DATA
214-2.0.0 RSET NOOP QUIT HELP VRFY
214-2.0.0 EXPN VERB ETRN DSN AUTH
214-2.0.0 STARTTLS
214-2.0.0 For more info use "HELP <topic>".
214-2.0.0 To report bugs in the implementation send email to
214-2.0.0 sendmail-bugs@sendmail.org.
214-2.0.0 For local information send email to Postmaster at your site.
214 2.0.0 End of HELP info
help vrfy
214-2.0.0 VRFY <recipient>
214-2.0.0 Verify an address. If you want to see what it aliases
214-2.0.0 to, use EXPN instead.
214 2.0.0 End of HELP info
vrfy tkyte
252 2.5.2 Cannot VRFY user; try RCPT to attempt delivery (or try finger)
no not exactly what i want
rahul, July 21, 2004 - 5:00 am UTC
Hi Tom,
I know the functionality of vrfy function but what i am looking for is ow do i use it to check if the addredd is valid ? As far as have read about this package its mentioned that for a correct address it will return the user name I(nothing is mentioned about the wrong address).
One of the document saya it will return me 250 for correct.
Now i want a simple example which shows me how do i check it in a pl/sql.
I had tried to take the o/p in a variable but but that didn't work out.If i give it directly oracle returns error saying the function must be first declared.
So if you could give me some link or some pl/sql where
the vrfy function is used it would be very helpful to me.
Thanks,
Rahul.
July 21, 2004 - 8:28 am UTC
utl_smtp.vrfy is documented to be a funtion that returns a reply record. A reply record is documented to consist of the code returned (number) and the text of the message returned.
So, here is the above telnet example done up in plsql, based on things read from the documentation of utl_smtp:
ops$tkyte@ORA9IR2> create or replace
2 PROCEDURE verify( p_recipient IN VARCHAR2 )
3 as
4 l_mailhost VARCHAR2(255) := 'aria.us.oracle.com';
5 l_mail_conn utl_smtp.connection;
6 l_reply utl_smtp.reply;
7 BEGIN
8 l_mail_conn := utl_smtp.open_connection(l_mailhost, 25);
9 utl_smtp.helo(l_mail_conn, l_mailhost);
10 l_reply := utl_smtp.vrfy( l_mail_conn, p_recipient );
11 dbms_output.put_line( 'code = ' || l_reply.code );
12 dbms_output.put_line( 'text = ' || l_reply.text );
13 utl_smtp.quit(l_mail_conn);
14 end;
15 /
Procedure created.
ops$tkyte@ORA9IR2> exec verify('tkyte');
code = 252
text = 2.5.2 Cannot VRFY user; try RCPT to attempt delivery (or try finger)
PL/SQL procedure successfully completed.
Not sure why this is mystifying???
thanks
Rahul, July 21, 2004 - 10:12 am UTC
Hi Tom,
Thanks for the reply. The whole thing was mystifying for i was assigning the o/p to a varchar2. Thanks once again.
tarun Vashistha, March 28, 2006 - 1:41 pm UTC
Mike, I am developing a procedure to pick the mail ids from my customer table and send them mail using UTL_SMTP, your site was very helpful in developing the code, I am just missing one functionality in my programs I want to track whether mail has been delivered to the customer or bounced back because of invaild mail id is there any way to verify that. I used you procedure....
create or replace
2 PROCEDURE verify( p_recipient IN VARCHAR2 )
3 as
4 l_mailhost VARCHAR2(255) := 'LocalHost';
5 l_mail_conn utl_smtp.connection;
6 l_reply utl_smtp.reply;
7 BEGIN
8 l_mail_conn := utl_smtp.open_connection(l_mailhost, 25);
9 utl_smtp.helo(l_mail_conn, l_mailhost);
10 l_reply := utl_smtp.vrfy( l_mail_conn, p_recipient );
11 dbms_output.put_line( 'code = ' || l_reply.code );
12 dbms_output.put_line( 'text = ' || l_reply.text );
13 utl_smtp.quit(l_mail_conn);
14 end;
15 /
Procedure created.
ops$tkyte@ORA9IR2> exec verify('vashisthatarun@rediffmail.com');
code = 252
text = 2.5.2
PL/SQL procedure successfully completed.
ops$tkyte@ORA9IR2> exec verify('vashisthatarunabcd99231@rediffmail.com');
code = 252
text = 2.5.2
PL/SQL procedure successfully completed.
there was no difference in 2 vashisthatarunabcd99231 is not a valid email id. how can I track whether the mail has been delivered to recipient or bounced back.
many thanks for your help.
March 28, 2006 - 8:06 pm UTC
you cannot really - the verify just says "ok, it is an email address". You would have to have the errors to set up and process bounced emails
to - tarun Vashistha
reader, March 29, 2006 - 3:29 am UTC
But who is Mike ???
Tarun Vashistha, March 29, 2006 - 9:00 am UTC
First off, Thanks a lot for reply i had never expected such a fast reply.
Second : sorry, while posting this qustion I was talking to mike and by mistake typed his name here.
Third :
Tom,
can you guide me in writing a procedure which check that a mail has been delivered to Recipient or bounced back and return some value in case of failure or success.
Thanks.
March 29, 2006 - 11:07 am UTC
not really, you would have to set up an email address on your server, have the errors boucne to that email address, read that inbox, process the bounced emails.
sort of "not in the domain of a database problem" at that point - but that is the gist of what you would do. You have to process the exceptions (the errors) that bounce back to you.
Capturing bounced emails
SAGAR, May 23, 2009 - 3:40 am UTC
Hi Tom,
How can i caputure the bounced emails and how can i redirect it.
Please help on this
May 23, 2009 - 10:36 pm UTC
you would have to write a program that would log into your email account that received the bounced emails, read them and process them
in other words, you wouldn't be in the database anymore, you should ask someone that writes code outside of the database to help you. You'll need to use some IMAP or POP API to read the inbound mails and do something...