The follwing sample code uses predefined package UTL_SMTP to send mail.
This package was first available in the version 8.1.7 . -
create or replace procedure sendmail(sender varchar2,recipient varchar2,subject varchar2, text
-
-
varchar2)
-
IS
-
mailhost VARCHAR2(64) := '192.168.1.32';
-
--The name of the SMTP server host
-
port constant number(2):=25;
-
--The port number on which SMTP server is listening (usually 25).
-
timeout number :=180;
-
--The time in seconds that the UTL_SMTP package waits before giving up in a read or write
-
-
operation in this connection.
-
--In read operations, this package gives up if no data is available for reading immediately.
-
--In write operations, this package gives up if the output buffer is full and no data is to be
-
-
sent into the network without being blocked.
-
--Zero (0) indicates not to wait at all.
-
--NULL indicates to wait forever.
-
mail_conn utl_smtp.connection;
-
BEGIN
-
--dbms_output.put_line(UTL_SMTP.VRFY (mail_conn,recipient));
-
mail_conn := utl_smtp.open_connection(mailhost, port,timeout);
-
--Helo performs initial handshaking with SMTP server after connecting
-
utl_smtp.helo(mail_conn, mailhost);
-
--Mail Initiates a mail transaction with the server
-
utl_smtp.mail(mail_conn, sender);
-
--Specifies the recipient of an e-mail message
-
utl_smtp.rcpt(mail_conn, recipient);
-
-- open_data(), write_data(), and close_data() into a single call to data().
-
--Sends the DATA command
-
utl_smtp.open_data(mail_conn);
-
utl_smtp.write_data(mail_conn,'From'||':'|| Sender || UTL_TCP.CRLF);
-
utl_smtp.write_data(mail_conn,'To'||':'|| recipient || UTL_TCP.CRLF);
-
utl_smtp.write_data(mail_conn,'Subject' ||':'|| subject || UTL_TCP.CRLF);
-
--Writes a portion of the e-mail message
-
utl_smtp.write_data(mail_conn, text);
-
--Closes the data session
-
utl_smtp.close_data(mail_conn);
-
utl_smtp.quit(mail_conn);
-
--dbms_output.put_line('Your message has been sent...!');
-
EXCEPTION
-
WHEN UTL_SMTP.PERMANENT_ERROR THEN
-
BEGIN
-
utl_smtp.quit(mail_conn);
-
END;
-
RAISE_APPLICATION_ERROR(-20101,'This id has Permanent Error');
-
WHEN UTL_SMTP.TRANSIENT_ERROR THEN
-
BEGIN
-
utl_smtp.quit(mail_conn);
-
END;
-
RAISE_APPLICATION_ERROR(-20102,'SMTP transient error:');
-
WHEN UTL_SMTP.INVALID_OPERATION THEN
-
BEGIN
-
utl_smtp.quit(mail_conn);
-
END;
-
RAISE_APPLICATION_ERROR(-20103,'Invalid Operation in Mail using UTL_SMTP.');
-
WHEN OTHERS THEN
-
RAISE_APPLICATION_ERROR(-20104,'Some other Error ...!');
-
end;
-
/
-
-
To execute the above procedure try the following code. -
exec sendmail('sender@sender.com','recipient@recipient.com','Hi','Test Mail');
-
0 16376 Sign in to post your reply or Sign up for a free account.
Similar topics
by: savvy |
last post by:
i'm trying to compile a simple console application for sending a mail,
my main idea is to schedule it to a particular time for sending mails
using the windows schedular task lateron. Therefore i...
|
by: Mr. x |
last post by:
Hello,
I am sending emails with Hebrew contents.
When receiving emails - I cannot see the Hebrew characters (it is not
outlook express configuration, because when receiving emails from friends -...
|
by: B-Dog |
last post by:
I've built a small app that sends mail through our ISP's SMTP server but
when I try to send through my local exchange server I get CDO error. Does
webmail use SMTP or does it strictly rely on...
|
by: Ant |
last post by:
Hi, I'm using the MailMessage & smtpMail classes in System.Web.Mail to send
mail, however it's not sending any emails.
I'm using it on a Windows 2003 server.
The simplest way to use this is...
|
by: HoustonComputerGuy |
last post by:
I am working on getting my web applications moved to .Net 2.0 and am
having some problems with System.Net.Mail. I get the following error
when sending the mail:
System.Net.Mail.SmtpException was...
|
by: Anuradha |
last post by:
Dear All
How can i send mails using vb.net
Thanx all
|
by: Eric Sheu |
last post by:
Greetings,
I have been searching the web like mad for a solution to my SMTP problem. I
am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a
web site I have created to...
|
by: mfleet1973 |
last post by:
Hello Again.
I have a program that sends e-mails as follows:
Try
Dim mail As New MailMessage
mail.To = "me@comp.com"
mail.From = "me@comp.com
mail.Subject = "Test"
mail.Body = "Testing123"
|
by: Robert Dufour |
last post by:
Dim message As New MailMessage("mymail@mydomain.com", "mymail@mydomain.com",
"Test", "Test")
Dim emailClient As New SmtpClient("localhost")
emailClient.Send(message)
The IIS server is...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |