Solved

Problem sending Email from Oracle(UTL_SMTP)

Posted on 2008-10-20
4
1,331 Views
Last Modified: 2013-12-07
hi,
I am trying to send a mail from Oracle (UTL_SMTP).
Mail is getting sent, but Body of the email is ABSENT (Subject is present).
Code is as follows
BEGIN
      --Creating a connection with SMTP Server
      g_mail_conn := UTL_SMTP.open_connection (g_s_mailhost, 25);
      --Handshaking
      UTL_SMTP.helo (g_mail_conn, g_s_mailhost);
      --Setting the FROM ID
      UTL_SMTP.mail (g_mail_conn, p_i_msg_from);
      --Setting the TO ID
      UTL_SMTP.rcpt (g_mail_conn, p_i_msg_to);
      --Preparing the mail
      l_mesg :=
            'Date: '
         || TO_CHAR (SYSDATE, 'dd Mon yy hh24:mi:ss')
         || 'From: '
         || p_i_msg_from
         || UTL_TCP.crlf
         || 'To: '
         || p_i_msg_to
         || UTL_TCP.crlf
         || 'Subject: '
         || p_i_msg_subject
         || UTL_TCP.crlf
         || p_i_msg_text;
      --Setting the format of the mail as HTML
      UTL_SMTP.DATA (g_mail_conn,
                       'MIME-Version: 1.0'
                     || CHR (13)
                     || CHR (10)
                     || 'Content-type: text/html'
                     || CHR (13)
                     || CHR (10)
                     || l_mesg || CHR (13)
                    );
      --Closing the connection
      UTL_SMTP.quit (g_mail_conn);


There are some other procs also for sending mail.
They used to work fine earlier.
But now SMTP server is reconfigured for the machine.

Please help.
Thanks
0
Comment
Question by:bhavanisharansingh
  • 3
4 Comments
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 22757547
rather than trying to put all of the header and body together using the DATA routine,  try splitting it into pieces.   not only will this reduce the likelihood of varchar2 overflow from concatenation, but it will also allow you to pinpoint where in the procedure the errors are occuring.


try this...
BEGIN

    --Creating a connection with SMTP Server

    g_mail_conn   := UTL_SMTP.open_connection(g_s_mailhost, 25);

    --Handshaking

    UTL_SMTP.helo(g_mail_conn, g_s_mailhost);

    --Setting the FROM ID

    UTL_SMTP.mail(g_mail_conn, p_i_msg_from);

    --Setting the TO ID

    UTL_SMTP.rcpt(g_mail_conn, p_i_msg_to);

    --Preparing the mail
 

    UTL_SMTP.open_data(g_mail_conn);

    UTL_SMTP.write_data(g_mail_conn,

                        'Date: ' || TO_CHAR(SYSDATE, 'dd Mon yy hh24:mi:ss') || UTL_TCP.crlf);

    UTL_SMTP.write_data(g_mail_conn, 'From: ' || p_i_msg_from || UTL_TCP.crlf);

    UTL_SMTP.write_data(g_mail_conn, 'To: ' || p_i_msg_to || UTL_TCP.crlf);

    UTL_SMTP.write_data(g_mail_conn, 'Subject: ' || p_i_msg_subject || UTL_TCP.crlf);

    UTL_SMTP.write_data(g_mail_conn, 'MIME-Version: 1.0' || UTL_TCP.crlf);
 

    UTL_SMTP.write_data(g_mail_conn, 'Content-type: text/html' || UTL_TCP.crlf);
 

    UTL_SMTP.write_data(v_connection, UTL_TCP.crlf);
 

    UTL_SMTP.write_data(g_mail_conn, p_i_msg_text);
 

    UTL_SMTP.write_data(v_connection, UTL_TCP.crlf);
 

    --Closing the connection

    UTL_SMTP.close_data(v_connection, UTL_TCP.crlf);

    UTL_SMTP.quit(g_mail_conn);

Open in new window

0
 

Author Comment

by:bhavanisharansingh
ID: 22764162
Thats great. It worked buddy. Thanks a lot :).
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 22764301
glad I could help, just accept the above answer and assign a grade to close the question
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 22764467
why only a B?  if it worked and was complete, it should have been an A.  

If you needed more, you only needed to ask.  Please don't assign penalties without giving the volunteers (not just me) a chance to complete your answer.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Subquery in Oracle: Sub queries are one of advance queries in oracle. Types of advance queries: •      Sub Queries •      Hierarchical Queries •      Set Operators Sub queries are know as the query called from another query or another subquery. It can …
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now