How to send email using pl/sql containing the result set as the msg body

Hi.. im using Pl/SQL code to send emails to the users from a dataset that is obtained in a databse table. i have used utl_smtp commands to establish the connection with the smtp mail server. im stuck at the logic when i have to include the message body which is actually the result set of a table.. For instance
IF (p_message = 0) THEN
UTL_SMTP.write_data(l_mail_conn, 'There is no mismatch between the codes' || UTL_TCP.crlf);
ELSE
UTL_SMTP.write_data(l_mail_conn, 'The missing codes are ' || UTL_TCP.crlf);
for s in (select * from temp)
loop
UTL_SMTP.write_data(l_mail_conn, ' ' ||s || UTL_TCP.crlf);
end loop;
END IF;
UTL_SMTP.close_data(l_mail_conn);
UTL_SMTP.quit(l_mail_conn);
END;
***p_message is a prameter passed to this procedure..
Can i obtain the result in the form i have it in my table. which has three columns. I want to display the three columns as it is with teh records. ?

this is not related about this forum but you can use below,
CREATE OR REPLACE PROCEDURE SEND_MAIL (subject varchar2,mail_from varchar2, mail_to varchar2,mail_msg varchar2)
IS
mail_host varchar2(30):='XXXXX';
mail_conn utl_smtp.connection;
tz_offset number:=0;
str varchar2(32000);
BEGIN
begin
select to_number(replace(dbtimezone,':00'))/24 into tz_offset from dual;
exception
when others then
null;
end;
mail_conn:=utl_smtp.open_connection(mail_host, 25);
utl_smtp.helo(mail_conn,mail_host);
utl_smtp.mail(mail_conn,'[email protected]');
utl_smtp.rcpt(mail_conn,mail_to);
utl_smtp.open_data(mail_conn);
utl_smtp.write_data(mail_conn,'Date: '||to_char(sysdate-tz_offset,'dd mon yy hh24:mi:ss')||utl_tcp.crlf);
utl_smtp.write_data(mail_conn,'From: '|| mail_from ||utl_tcp.crlf);
utl_smtp.write_data(mail_conn,'To: "'|| mail_to ||'" <'||mail_to||'>'||utl_tcp.crlf);
utl_smtp.write_data(mail_conn,'Subject: '||subject||utl_tcp.crlf);
utl_smtp.write_data(mail_conn,utl_tcp.crlf);
utl_smtp.write_data(mail_conn,replace_turkish_chars(mail_msg)||utl_tcp.crlf);
utl_smtp.write_data(mail_conn,utl_tcp.crlf);
utl_smtp.close_data(mail_conn);
utl_smtp.quit(mail_conn);
END;
Edited by: odilibrary.com on Jun 12, 2012 5:26 PM

Similar Messages

  • How to send emails using java code

    Hi,
    can any give me some sample code for sending emails using java language

    JavaMail quick start
    jGuru: Fundamentals of the JavaMail API

  • How to send email via PL/SQL

    Hi guys,
    I have already read several topics about that subject. However, I haven't understood well. It is very complicated. Could somebody explain step by step or show a detail source about sending email through pl/sql?
    Thanks alot.

    876928 wrote:
    I have tried it, but I get this error.
    ora-29278 smtp transient error 421 service not available
    By the way I use gmail, I don't know how I change my settings? I mean Ain't I suppose to type my mails pass and username ?
    gmail won't forward your SPAM.
    you need to utilize local Mail Transport Agent that is explicitly configured to relay messages from DB Server

  • How to send emails using JSP?

    How can i send emails using JSP? what are the things that i will need? please help me asap...thanks

    Hi,
    This works for me:
    <%
    String from = "Person"
    String to= "my-email-address;
    try{
    SmtpClient client = new SmtpClient("smtp.stuff.com");
    client.from(from);
    client.to(to);
    PrintStream message = client.startMessage();
    message.println("To: " + to);
    message.println("Subject: Sending an e-mail");
    message.println();
    message.println("Groovy :-)");
    client.closeServer();
    catch (IOException e){
    System.out.println("ERROR SENDING EMAIL: "+e);
    %>

  • How to send emails from HANA SQL Console

    Hi,
    Please guide how  to send mail from HANA Studio SQL Console.
    Is there any standard procedure in Hana Studio to send Mail( e.g. in MS SQL  "sp_send_dbmail" Procedure)

    Hi Preethi,
    Please go through the attached link:
    How to send emails from HANA
    Regards,
    Krishna

  • How to Colour the fields in the Result Set of the query

    Hi all,
    I am having a requirement wher the user want to view the queries results with some colour to the char in the result set.
    suppose customer is the row he want to view some customers with one color and some with different color.
    Is it possible in Bi.
    If so Plz let me know
    Regards

    Hi Priya,
    for the macro thing, you will have to create a workbook and store your query into it, because macros are attached to only workbooks and not queries.
    in the workbook screen (i.e. excel), go to tools --> Macro --> Visual Basic Editor. or simply press Alt + F11. this will take you to macro editor screen.
    you can use code that may look something like below to color the columns, you can also give constant column if they are fixed.
    sub ColorColumns(rngTarget As Range, _
        intColor As Integer)
    Dim c As Long
        With rngTarget
            .Interior.ColorIndex = intColour
            Next c
        End With
    End Sub
    You will find some easy and short snippets for this.
    Regards,
    Purvang

  • Sending email using PL/SQL based on a query result

    Hello all,
    I want to create a procedure using PL/SQL, based on a query result.Here is the scenario:
    I have multiple tables in Target and Source databases that I want to compare(not the whole table but queries on these tables) and if they differ, I want to shoot an email. I have some ideas how to implement this but not sure whether it is the best approach.
    select Acct_id, total from SourceTableA
    minus
    select Acct_id, total from TargetTableA
    select Acct_id, sum from SourceTableB
    minus
    select Acct_id, sum from TargetTableB
    If the result of any of above queries > 0 then I want to shoot an email and want to repeat this procedure in the morning every day.
    I know how to implement send_mail procedure using UTL_SMTP package and how to schedule tha job by dbms_job package. But I am not sure how to implement the result of minus query. In case if minus > 0 then I also want to send the name of tables in the email message where source and target tables are not same. Should i use cursor, variable or insert the result in a new table? any help would be highly appreciated. Thanks in advance.
    Khan

    Actually these queries are the part of our daily testing that we run everyday manually(after the scheduled ETL load) to see if there are any discrepencies between our datawarehouse tables and source tables. So instead of running these queries manually everyday we want to schedula a procedure that will shoot an email in case of any discrepency and indicate which tables have problems.

  • Cannot send email using PL/SQL through Enterprise Manager 10g

    Hi
    I need to schedule a job that sends email periodically. I am using the scheduler in Oracle Enterprise Manager 10g for this. For sending the email, I am creating a PL/SQL job. The code is as follows:
    PROCEDURE send_test_message
    IS
    mailhost := 'iwblrcormsg001.sci.local';
    sender := '[email protected]';
    recipient := '[email protected]';
    mail_conn utl_smtp.connection;
    BEGIN
    mail_conn := utl_smtp.open_connection(mailhost, 25);
    utl_smtp.helo(mail_conn, mailhost);
    utl_smtp.mail(mail_conn, sender);
    utl_smtp.rcpt(mail_conn, recipient);
    utl_smtp.open_data(mail_conn);
    utl_smtp.write_data(mail_conn, 'This is a test message.' || chr(13));
    utl_smtp.write_data(mail_conn, 'This is line 2.' || chr(13));
    utl_smtp.close_data(mail_conn);
    utl_smtp.quit(mail_conn);
    END;
    I have setup the smtp server and received a test email from the EM notifying me of successful configuration. When the above job is run, the scheduler shows status as successful. If I go to the command step, it displays the following output:
    Output Log
    SQL*Plus: Release 10.1.0.2.0 - Production on Thu Feb 19 19:04:29 2009
    Copyright (c) 1982, 2004, Oracle. All rights reserved.
    SQL> SQL> SQL> SQL> Connected.
    SQL> SQL> 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 Disconnected from Personal Oracle Database 10g Release 10.1.0.2.0 - Production
    With the Partitioning, OLAP and Data Mining options
    Now, the only issue is that I do not receive any email at the address specified! I would be very grateful if someone could point out the error here.

    I would use APEX4.0 for this.
    Create an interactive report based on your data. Add a chart to that report and use the NOTIFY feature to send you the email.

  • How to send email using u201CSO_DOCUMENT_SEND_API1u201D without attachment.

    Dear Expert,
    I am using the folowing code to get the content of smartform as otfdata :
          CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
            EXPORTING
              formname           = v_formname
            IMPORTING
              fm_name            = v_fm_name
            EXCEPTIONS
              no_form            = 1
              no_function_module = 2
              OTHERS             = 3.
          CALL FUNCTION v_fm_name
            EXPORTING
             control_parameters         = control_parameters
             output_options             = output_options
          orderadm_h = orderadm_h
          activity_h =  activity_h
          status_i = status_i
          working_set_e_s_bbp = working_set_e_s_bbp
          language = l_langu  "sY-LANGU
           IMPORTING
             document_output_info       = document_output_info
             job_output_info            = job_output_info
             job_output_options         = job_output_options
           EXCEPTIONS
             formatting_error           =  1
             internal_error             =  2
             send_error                 =  3
             user_canceled              =  4
             OTHERS                     =  5
    How can I send the data in job_output_info-otfdata in the email body without putting it into attachment?
    I am using the function u201CSO_DOCUMENT_SEND_API1u201D.
    I am sending also a normal text in the email and I want to put the data in the job_output_info-otfdata at the end of the text.
    Thank for very much in advance.
    Best regards
    Ahmed Hadi

    Hi Ahmed,
    I believe this blog will help you:
    http://www.sdn.sap.com/irj/scn/weblogs;jsessionid=%28J2EE3417800%29ID1330314450DB01968839116473008128End?blog=/pub/wlg/2273
    Kind regards,
    Garcia

  • How to send emails using Automatic Work Items in Collections using XML Publ

    Hi,
    We are using XML Publisher to send correspondances in Advanced Collections.
    We want to send email correspondances using Automatic Strategy Work Items.
    Can anybody please help on how to send these?

    I believe you have to define your dunning template and assign that template to the strategy work item.
    Let me know if you are still not able to do it.
    Thanks,
    Anil

  • Send Email using Execute SQL Task??????

    I need to send the bad records in the data flow.  I am attempting to do this using Execute SQL Tasks.  Please give me steps I need to accomplish this.  I have not set any variables up yet, assuming I need too.

    Just add a Send mail Task (or Script Task if using gmail etc which requires authentication) and pass the file as an attachment. Make sure you've a step (Script Task) to check if file length > 0 (ie file has records) before you link it to Send mail Task
    ie use a conditional precedence constraint (Expression And Constraint option)
    See these links for more details
    http://dwteam.in/send-mail-in-ssis-using-gmail/
    http://www.mssqltips.com/sqlservertip/1753/sending-html-formatted-email-in-sql-server-using-the-ssis-script-task/
    https://www.simple-talk.com/sql/ssis/working-with-precedence-constraints-in-sql-server-integration-services/
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to send email using SPUtility.SendEmail method

    hi all,
             I am using SPUtility.SendEmail method to send email to list of users. but i am unable to send it. Code is not throwing any kind of error. Can anyone guide me steps to send email programmatically .
    Regards,
    Milan C.

    Hello Milan, 
    Humm, 
    Problably code is correct, need to speak with System administrator of mail server/exchange to know what rules exist on server mail.
    Verify if server mail validate IP from server to allow send mail. 
    Verify if exist some rule from server mail that validate sender with some domain "[email protected]"
    Verify if Email server have relay active to send Emails externaly
    Verify what type of authentication exist on you server Email, "Anonymous access or Login as password access", https? port number?
    This info is very important to have before you configure emails on sharepoint, to preview problems....  
    André Lage Microsoft SharePoint, CRM and Sybase Consultant
    Blog:http://aaclage.blogspot.com
    Codeplex:http://spupload.codeplex.com/http://simplecamlsearch.codeplex.com/

  • How we send email from pl/sql

    i want 2 send mail from pl/sql??
    plz tell me bout d coding related to this.
    i really appreciated ur help.

    Try the pl/sql code below.
    create or replace PROCEDURE send_test_message
    IS
    mailhost VARCHAR2(64) := '191.168.251.207'; -- ip address of the mail server.
    sender VARCHAR2(64) := '[email protected]';
    recipient VARCHAR2(64) := '[email protected]';
    mail_conn utl_smtp.connection;
    BEGIN
    mail_conn := utl_smtp.open_connection(mailhost, 25);
    utl_smtp.helo(mail_conn, mailhost);
    utl_smtp.mail(mail_conn, sender);
    utl_smtp.rcpt(mail_conn, recipient);
    utl_smtp.open_data(mail_conn);
    utl_smtp.write_data(mail_conn, 'Your leave is Cancelled due to xyz...reason ' || chr(13));
    utl_smtp.write_data(mail_conn, 'This is line 2.' || chr(13));
    utl_smtp.close_data(mail_conn);
    utl_smtp.quit(mail_conn);
    EXCEPTION
    WHEN OTHERS THEN
    -- Insert error-handling code here
    NULL;
    END;

  • How to send email using forms in cq5 to anonymoys user?

    Hello,
    I need to send mail from a popup form in CQ5.6 to anonymous users on any domains like gmail,yahoomail etc.
    I config the admin console properties of the DAY CQ Mail service.
    SMTP server details:-smtp.gmail.com
    port 465
    I create a form on a page ans define action as MAIL.After sending the mail it will redirect to the thank you page.
    My concern is when i am submitting the mail via send button it will not work.I am not getting any response in inbox of the user.
    Do anyone have idea for the same?
    Thanks in advance

    If your form is running on a box which can mail from the command line you can also do it from a host command. For example, we mail from our web forms solaris middle tier with
    HOST('echo "First line of text'||chr(10)||
    'Second Line of text " | mailx -s "Subject" Address');
    Solaris automatically sends this to our exchange server identified as mailhost in the hosts file.

  • How to send emails from an iPad to a group set up in contacts?

    Apple Contacts "groups" show up in iOS7 contacts on my iPad, synced from iMac. 
    But I cannot get the group list of contacts to enter automatically into "to" on the iPad as happens automatically on the desktop iMac.  So the "groups" on the iPad really doesn't have any functionality other than giving one a list of who is in a group per my assignment on my iMac.
    So I end up entering manually each individual in a group in the "to" line when I want to send an email to a group from my iPad. On the iMac, selecting a contacts group will automatically list the addresses of the people I have put into a group.  A known problem, and any solution?

    Thanks.  So matters haven't changed.  Ipad and iohone systems still not make use of the groups created in OSX Contacts, although one can "see" the groups synced through iCloud.  They just do not function as real distribution lists in Mail.
    With the Mailshot app, one creates Mailshot groups with Mailshot group name.  It's as smooth as a work around can get.
    Silly that Apple iOS folks never got around to connecting the contact groups now listed in iOS Contacts through iCloud syncing to also be fully functional in iOS Mail for the purpose of group emailing. 

Maybe you are looking for