Send Email Hangs - UTL_SMTP

Hi All,
I am tryin to write a package to send email notifications, when i try to execute this package it just hangs and never sends any email. Any taughts why this is happening.
create or replace package body
pm.email_pkg
is
-- Email Package
mv_r varchar2(2) := utl_tcp.crlf;
procedure send_mail
sender in varchar2,
recipient in varchar2,
subject in varchar2 default null,
message in varchar2
is
mailhost varchar2(30) := util_pkg.f_sysinfo('SMTP');
smtpport number := util_pkg.f_sysinfo('SMTP_PORT');
mail_conn utl_smtp.connection;
begin
mail_conn := utl_smtp.open_connection(mailhost, smtpport);
utl_smtp.helo(mail_conn, mailhost);
utl_smtp.mail(mail_conn, sender);
utl_smtp.rcpt(mail_conn, recipient);
--utl_smtp.data ( mail_conn, 'Subject : '|| subject || mv_r || mv_r || message );
utl_smtp.open_data(mail_conn) ;
utl_smtp.write_data(mail_conn, 'Subject : '|| subject || mv_r || mv_r || message );
utl_smtp.close_data(mail_conn);
utl_smtp.quit(mail_conn);
exception
when others then
-- handle the error
null;
end send_mail;
procedure taskemail
is
cursor c_tasks is
select t.name, t.techuser, t.projectid, p.name pname, t.assigndate, t.descr
from tasks t, projects p
where t.projectid = p.projectid
and trunc(t.created) = trunc(sysdate);
cursor c_notify (pv_user varchar2) is
select id
from notifications
where owner = pv_user
and notid = util_pkg.f_sysinfo('TASK_NOTIFY');
mv_sender varchar2(64) := util_pkg.f_sysinfo('SENDER_EMAIL');
mv_recipient varchar2(64);
mv_subject varchar2(100) ;
mv_message varchar2(4000);
begin
for i in c_tasks
loop
select email
into mv_recipient
from user_info
where user_name = i.techuser;
if mv_recipient is not null then
mv_subject := 'Assigned to:' || i.name;
mv_message := 'You have been Assign the following Task' || mv_r;
mv_message := mv_message || mv_r;
mv_message := mv_message || 'Task: ' || i.name || mv_r;
mv_message := mv_message || 'Project ' || i.pname || mv_r;
mv_message := mv_message || mv_r;
mv_message := mv_message || 'Description:' || mv_r ;
mv_message := mv_message || i.descr;
for j in c_notify(i.techuser)
loop
email_pkg.send_mail(mv_sender, mv_recipient, mv_subject, mv_message);
end loop;
end if;
end loop;
end taskemail;
procedure email_notifications
is
begin
email_pkg.taskemail;
end;
end email_pkg;
show errors

SQL> begin
2 email_pkg.email_notifications;
3 end;
4 /
begin
ERROR at line 1:
ORA-29531: no method get_crlf in class oracle/plsql/net/TCPConnection
ORA-06512: at "SYS.UTL_TCP", line 559
ORA-06512: at "SYS.UTL_TCP", line 552
ORA-06512: at "PM.EMAIL_PKG", line 7
ORA-06512: at line 2

Similar Messages

  • 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:
    Monk

    look 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

  • Send email hangs program

    At first, oracle change this site a lot. I logged into this site after a long time and I was amazed to see the new changes. Moving onto the the question.
    I am developing a spring mvc web application. The problem is when I send email, let say to more than 4 person, the program hangs for a while. Some friend told me to use thread pool to solve this. What is the general practice for handling this kind of situation?
    Thanks

    If its really an issue of sending mail, then the suggestion of your friend is good. Or you can create a queue to drop the mail and a queue lookup class which should periodically look into the queue and send it if any mail exist  .

  • Sending email hangs Mail

    I have done my best to scour the discussions for an answer to this problem, but if I have somehow overlooked it, then I will be happy to just follow any links people have.
    My problem: About 80% of the time, sending email causes Mail to hang with a permanent beachball. My solution is to force quit and relaunch Mail. At this point, it finishes sending and behaves normally. Although often, recipients will tell me they got my email twice.
    Actions taken so far: I have rebuilt all potentiall affected mailoboxes. I have trashed the Outbox entirely. I have trashed my Junk mail filters. I have used utilities to scan for corrupted preferences. Probably other things that I have forgotten at this point.
    It's a basic POP/SMTP setup.
    Having invested about 30 hours so far in transitioning to Mail from being a long time Eudora user, this dealbreaker is really getting to me. If there is anyone here who can offer some assistance, I would be most grateful.
    TIA.
    Powerbook G4   Mac OS X (10.4.6)  

    2. In the Finder, go to HOME/Library/Mail/POP-username@servername/. With
    that folder open, do Edit > Select All (⌘A), then Edit > Copy (⌘C), and paste
    it in your reply to this post, to let me see whether there is something amiss
    within your account folder.
    Deleted Messages.mbox
    Drafts.mbox
    INBOX.mbox
    Junk.mbox
    MessageUidsAlreadyDownloaded2
    Sent Messages.mbox
    3. Move Sent Messages.mbox to the Desktop, open it, and repeat the same
    procedure to let me see which files and folders are within Sent
    Messages.mbox.
    Messages
    Info.plist
    The messages folder itself is empty. I routinely move sent mail to other mailboxes.
    4. Open Mail and check whether it works properly now.
    Thank you for your persistance.
    Because I clean out my sent and drafts folders, I have essentially run this test more than once already. (Quitting Mail. Trashing some mailboxes. Restarting Mail.) Things seem ok for a time, but you have to remember that this problem is intermittant, albeit frequent.

  • Sending Email Hangs

    Hello,
    I have created a send email process with multiple attachments. I allow the user to enter free form text of 4000 chars. I have created a page process, before the send email process to split out the text into 1000 char chunks of data and recompiled back together into :P4_MSG_BODY text box. For the most part the process works fine, except it hangs sometimes, and the dba will see that the process is cpu intensive. I cannot figure out what would be causing this problem. I am using 10g, with Apex 3.2.1. Please advise. Code below.
    declare
    inc number :1;
    body_length number :=0;
    tmp_chunk number :=1;
    v_body varchar2(4005);
    final_chunk number :=0;
    crlf char(2) := chr(10)||chr(13);
    begin
      v_body := :P4_MSG_BODY;
      body_length := length(:P4_MSG_BODY);
    loop
      if ((tmp_start + 999) > body_length) then
        v_body := substr(:P4_MSG_BODY,1,body_length - tmp_start);
      final_chunk :1;
    else
      v_body := substr(:P4_MSG_BODY, tmp_start, 998);
      end if;
    loop
       if substr(:P4_MSG_BODY, inc, 1) = ' ' then
      exit;
      end if;
      inc := inc-1;
    end loop;
    v_body := substr(:P4_MSG_BODY, tmp_start, 998+inc);
    tmp_start := tmp_start + 999 + inc;
    if tmp_chunk = 1 then
        :P4_MSG_BODY1 := v_body;
    elsif tmp_chuck = 2 then
        :P4_MSG_BODY2 :=v_body;
    elsif tmp_chunk =3 then
      :P4_MSG_BODY3 = := v_body;
    else
      :P4_MSG_BODY4 := v_body;
    end if;
    tmp_chunk := tmp_chunk + 1;
    inc := -1;
    if(final_chunk = 1) then
    exit;
    end if;
    end loop;
    :P4_MSG_BODY := :P4_MSG_BODY1||crlf||:P4_MSG_BODY2||crlf||:P4_MSG_BODY3||crlf||:P4_MSG_BODY4||crlf;Thanks,
    Mary
    Edited by: MaryM on Jul 25, 2011 4:11 PM

    This doesn't happen all of the time. I am able send out many emails and all of the sudden it will hang on the process. Then I will cancel it and resubmit the same thing and it works fine. I thought it was network glitch, but I'm not sure what is causing this strange behavior.
    The databse is configured for email. I am able to send an email to multiple recipients, with/without attachments.
    I cannot ping the servers until the dba is here. All I have is an Oracle Enterprise Manger SQL details showing me how it bogs down the server.
    Mary

  • Csnnot send email thru UTL_SMTP (PL-SQL)

    If I try to send an email thru SQL it will work, but If i convert it to a PROCEDURE and then execute it with "EXECUTE PD_EMAIL('TEST','TEST'); It will give me the same error:
    ORA-24247: network access denied by access control list (ACL)
    Please help, this is ORACLE STANDARD EDITION 11G R2
    The store procedure is as follows:
    Create or Replace Procedure Pd_Email (Gv_Subject VARCHAR2, Gv_Body VARCHAR2) Is
    Lv_From VARCHAR2(80) := '[email protected]';
    Lv_To VARCHAR2(500) := '[email protected]';
    Lv_Host VARCHAR2(30) := 'mail.myhost.com';
    Lv_Conn Utl_smtp.Connection;
    BEGIN
    Lv_Conn := utl_smtp.Open_Connection(Lv_Host, 25);
    utl_smtp.Helo(Lv_Conn, Lv_Host);
    utl_smtp.Mail(Lv_Conn, Lv_From);
    utl_smtp.Rcpt(Lv_Conn, Lv_To);
    utl_smtp.Data(Lv_Conn,
    'Date: ' || to_char(sysdate, 'Dy, DD Mon YYYY hh24:mi:ss') ||chr(13)||chr(10)||
    'From: ' ||Lv_From ||chr(13)||chr(10)||
    'Subject: '||Gv_Subject||chr(13)||chr(10)||
    'To: ' || Lv_To||chr(13)||chr(10));
    utl_smtp.Quit(Lv_Conn);
    EXCEPTION
    WHEN utl_smtp.Transient_Error OR utl_smtp.Permanent_Error then
    raise_application_error(-20000, 'Email Error: '||sqlerrm);
    END
    Your help with me be greatly appreciated it.

    Panamanian wrote:
    Ok, since it does work in SQL, but not in a table trigger (if inserting). What should I check? or what sql statement should I run? for testing purposes?It cannot work in SQL as the SQL language does not support defining and using tcp sockets. PL/SQL is needed for that.
    PL/SQL code is also what is used to define a trigger. So assuming the same schema is used, that PL/SQL code will be executed in the same environment irrespective of the call being via a trigger or via a normal database call.
    That aside - sending e-mails from triggers is a terrible idea. A trigger is NOT intended to be used for something like that.
    The transaction can be rolled back. The e-mail send cannot be undone - and en e-mail would have been send reporting on changes that never happened in the database.
    The same trigger can fire twice for the very same row and transaction under special circumstances in Oracle. Thus 2 e-mails reporting the very same change... a change that can still be rolled back. How does that make sense?
    The trigger can choke on mail errors. What then? Fail a perfectly valid business transaction that meets all consistency and validation rules, because the mail server is down, or there is a network problem or something?
    That is not how robust applications are designed and written.

  • I can't send email with arabic character

    Hi Every Body
    I tried to send email using utl_smtp but it didn't support arabic language.
    DECLARE
    conn utl_smtp.connection;
    BEGIN
    conn := demo_mail.begin_mail('[email protected]',
    '[email protected]',
    'test mail arabic',
    'text/plain;charset=1256');
    demo_mail.write_text(conn,'ÇÍãÏÇÐíß');
    demo_mail.end_mail(conn);
    END;
    I tried other way
    CREATE OR REPLACE procedure send_mail(sender in varchar2,
    recipicent in varchar2,
    subject in varchar2 default 'text/plain; charset=1256' ,
    message in varchar2) is
    mail_conn utl_smtp.connection;
    begin
    mail_conn := utl_smtp.open_connection('134.177.1.100');
    utl_smtp.helo(mail_conn, 'tpc.tatasteel.com');
    utl_smtp.mail(mail_conn, sender);
    utl_smtp.rcpt(mail_conn, recipicent);
    utl_smtp.open_data(mail_conn);
    utl_smtp.write_data(mail_conn, 'From:' || Sender || utl_tcp.CRLF);
    utl_smtp.write_data(mail_conn, 'To:' || recipicent || utl_tcp.CRLF);
    utl_smtp.write_data(mail_conn, 'Subject :' || subject || utl_tcp.CRLF);
    utl_smtp.write_data( mail_conn, 'MIME-version: 1.0' || message|| utl_tcp.CRLF);
    utl_smtp.write_data( mail_conn, 'Content-Type: text/plain; charset=Arabic(Windows)' || message || utl_tcp.CRLF);
    utl_smtp.write_data( mail_conn, 'Content-Transfer-Encoding: 8bit' || message|| utl_tcp.CRLF);
    utl_smtp.write_data(mail_conn,utl_tcp.CRLF);
    utl_smtp.close_data(mail_conn);
    utl_smtp.quit(mail_conn);
    EXCEPTION
    WHEN utl_smtp.transient_error OR utl_smtp.permanent_error THEN
    utl_smtp.quit(mail_conn);
    raise_application_error(-20000,'Failed to send mail due to the following error: ' ||sqlerrm);
    end send_mail;
    my NLS_LANG is: AMERICAN_AMERICA.AR8MSWIN1256
    please send to me a right script which can help me
    Thanks and Best Regards
    Ahmed Ismail

    Text (VARCHAR2) data sent using write_data() API is converted to US7ASCII before it is sent. If the text contains multibyte characters, each multibyte character in the text that cannot be converted to US7ASCII is replaced by a `?' character. If 8BITMIME extension is negotiated with the SMTP server using the EHLO() API, multibyte VARCHAR2 data can be sent by first converting the text to RAW using the UTL_RAW package, and then sending the RAW data using write_raw_data().
    Here is the link.
    http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96612/u_smtp2.htm#1000846

  • Sending email from oracle

    Hi all
    I have a requirement to send emails to managers internal to the company from oracle whenever the orders placed by customers are not acknowleded in certian time like within 6 hrs or so.I could figure out the logic but dont know how to send an email from oracle.
    my logic:
    creating a job which will be scheduled to run every 4 or 5 hrs.this job runs a stored procedure which does all the logic and sends an email.
    any suggesions or source is greatly appreciated.
    thanks and regards in advance
    yugandhar

    Hi,
    for scheduling a job use dbms_job package and to send emails use utl_smtp package is available oracle 8.1.6 and above hope this helps you
    prem

  • 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 you

    Simple 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 "&gt;" and "&lt;"
       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 html email using utl_smtp

    (Oracle 8.1.7)
    I'm using the following procedure to send an HTML formatted e-mail. It sends email but I'm seeing in Outlook html code instead of formatted mail. (It sends text like :
    a bit of text
    --a1b2c3d4e3f2g1
    content-type: text/html;
    <html><head></head><body><B>HELLO </B></body></html>
    a1b2c3d4e3f2g1
    What can I solve this problem?
    Thanks in advance...
    its usage :
    html_email('smo@....','smo2@...','This is a subject','a bit of text', '<html><head></head><body><B>HELLO </B></body></html>', 'some hostname',25);
    CREATE OR REPLACE procedure html_email(
    p_to in varchar2,
    p_from in varchar2,
    p_subject in varchar2,
    p_text in varchar2 default null,
    p_html in varchar2 default null,
    p_smtp_hostname in varchar2,
    p_smtp_portnum in varchar2)
    is
    l_boundary varchar2(255) default 'a1b2c3d4e3f2g1';
    l_connection utl_smtp.connection;
    l_body_html clob := empty_clob; --This LOB will be the email message
    l_offset number;
    l_ammount number;
    l_temp varchar2(32767) default null;
    begin
    l_connection := utl_smtp.open_connection( p_smtp_hostname, p_smtp_portnum );
    utl_smtp.helo( l_connection, p_smtp_hostname );
    utl_smtp.mail( l_connection, p_from );
    utl_smtp.rcpt( l_connection, p_to );
    l_temp := l_temp || 'MIME-Version: 1.0' || chr(13) || chr(10);
    l_temp := l_temp || 'To: ' || p_to || chr(13) || chr(10);
    l_temp := l_temp || 'From: ' || p_from || chr(13) || chr(10);
    l_temp := l_temp || 'Subject: ' || p_subject || chr(13) || chr(10);
    l_temp := l_temp || 'Reply-To: ' || p_from || chr(13) || chr(10);
    l_temp := l_temp || 'Content-Type: multipart/alternative; boundary=' ||
    chr(34) || l_boundary || chr(34) || chr(13) ||
    chr(10);
    -- Write the headers
    dbms_lob.createtemporary( l_body_html, false, 10 );
    dbms_lob.write(l_body_html,length(l_temp),1,l_temp);
    -- Write the text boundary
    l_offset := dbms_lob.getlength(l_body_html) + 1;
    l_temp := '--' || l_boundary || chr(13)||chr(10);
    l_temp := l_temp || 'content-type: text/plain; charset=us-ascii' ||
    chr(13) || chr(10) || chr(13) || chr(10);
    dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);
    -- Write the plain text portion of the email
    l_offset := dbms_lob.getlength(l_body_html) + 1;
    dbms_lob.write(l_body_html,length(p_text),l_offset,p_text);
    -- Write the HTML boundary
    l_temp := chr(13)||chr(10)||chr(13)||chr(10)||'--' || l_boundary ||
    chr(13) || chr(10);
    l_temp := l_temp || 'content-type: text/html;' ||
    chr(13) || chr(10) || chr(13) || chr(10);
    l_offset := dbms_lob.getlength(l_body_html) + 1;
    dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);
    -- Write the HTML portion of the message
    l_offset := dbms_lob.getlength(l_body_html) + 1;
    dbms_lob.write(l_body_html,length(p_html),l_offset,p_html);
    -- Write the final html boundary
    l_temp := chr(13) || chr(10) || '--' || l_boundary || '--' || chr(13);
    l_offset := dbms_lob.getlength(l_body_html) + 1;
    dbms_lob.write(l_body_html,length(l_temp),l_offset,l_temp);
    -- Send the email in 1900 byte chunks to UTL_SMTP
    l_offset := 1;
    l_ammount := 1900;
    utl_smtp.open_data(l_connection);
    while l_offset < dbms_lob.getlength(l_body_html) loop
    utl_smtp.write_data(l_connection,
    dbms_lob.substr(l_body_html,l_ammount,l_offset));
    l_offset := l_offset + l_ammount ;
    l_ammount := least(1900,dbms_lob.getlength(l_body_html) - l_ammount);
    end loop;
    utl_smtp.close_data(l_connection);
    utl_smtp.quit( l_connection );
    dbms_lob.freetemporary(l_body_html);
    end;

    There have been many very good threads on sending email using the UTL_SMTP on the forum including threads that deal with HTML formated mail.
    The basic process is to the same as with sending regular (non HTML) mail, but you add some additional headers to the mail message as well as additional formatting to the message body (e.g. HTML tags as needed).
    Specifically you need to add the two following headers:
    MIME-Version: 1.0
    Content-type: text/html

  • How to format and send html email using utl_smtp

    Hi,
    I need to send email in the html format from within the database using utl_smtp. I am really not interested in creating os level file using "set markup html on spool on" and sending that as an html attachment. Can someone please give a code?
    1. Output of a select needs to be emailed (for example : select empid, name from emp, salary)
    2. Certian cells for example salary < 4800 needs to be higlighted in Red color
    3. I need to send email which is having more than 32767 characters (I can not use varchar2 field)
    I have reffered to following url on asktom:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:1739411218448
    However it does not help.
    If someone has a sample code with any select from a table, it would be a great help.
    Regards
    Sudhanshu Bhandari

    There have been many very good threads on sending email using the UTL_SMTP on the forum including threads that deal with HTML formated mail.
    The basic process is to the same as with sending regular (non HTML) mail, but you add some additional headers to the mail message as well as additional formatting to the message body (e.g. HTML tags as needed).
    Specifically you need to add the two following headers:
    MIME-Version: 1.0
    Content-type: text/html

  • IPhone connections hangs when sending email after upgrade.

    After upgrading to 2.0 firmware on my first generation IPhone, the phone now regulary hangs when sending email via smtp. Even if I try to close the connection by putting it into AirPlane mode and back again it still hangs and from that point onwards doesn't check or send any new emails. If I then shut the phone down and restart it looses the email as it's not either in the sent or outbox folders. This has happened quite a few times since upgrading. Does anybody have any advice?

    Found this useful tidbit by mdwelsh231 on another thread:
    "I'm having this problem too. Rather than rebooting the phone, an even easier solution is to hold down the Home button for several seconds (I believe it's 8 sec) which will kill the Mail application and return you to the home screen. Restarting Mail (by tapping the Mail icon) will cause it to reconnect. I find that this resolves the connection hanging issue. However, it is still kind of a pain. I suspect a bug in the 2.0 iPhone firmware. "
    Worked for me
    Cheers,
    C

  • I am not able to send Photos via email any longer. I am able to send emails but if I try to send a photo attached it just hangs there in the outbox. I have tried the various options to re-boot ?

    I hope someone can help with this
    I am now unable to send any photos from my iPad2,  When I got this last December it worked fine and I could easily take a picture and send it.
    About a month ago I tried it and it and it failed, I was abroad and did not think it was a problem?
    Although I have not changed anything to my set up outhe than automatic software upgrades on the iPad it refuses to work.
    I can send emails without photos and tried rebooting and re setting the internet connection,
    The email just sits in the outbox and I get the following message?
    connection to the outgoing server "smtp. gmail.com" failed
    Any help or suggestions would be appreciated Thanks

    Thanks for replying and your time.
    Unfortunately no rebuild option in iphone 3gs

  • Cannot Send Email Notification Using Stored Procedure.

    Hi Friends,
    I tried to execute this job scheduler...
    begin
    dbms_scheduler.create_job(
    job_name => 'ILMS_JOB_SCHEDULE'
    ,job_type => 'PLSQL_BLOCK'
    ,job_action => 'begin ilms.check_reminder(); end; '
    ,start_date => SYSTIMESTAMP
    ,repeat_interval => 'FREQ=DAILY'
    ,enabled => TRUE
         ,end_date => NULL
    ,comments => 'Ilms job schedule for notification.');
    end;
    However, since the effect is too long I rescheduled the frequency to be every one minute in this set attribute...
    BEGIN
    DBMS_SCHEDULER.SET_ATTRIBUTE(
              name => 'ILMS_JOB_SCHEDULE'
              ,attribute => 'repeat_interval'
              ,value => 'FREQ=MINUTELY;INTERVAL=1'
    DBMS_SCHEDULER.DISABLE('ILMS_JOB_SCHEDULE');
    DBMS_SCHEDULER.ENABLE('ILMS_JOB_SCHEDULE');
    END;
    Check Reminder is the stored procedure invoked by job scheduler to check values in database columns before sending email notification to the respective recipients' email address and also the format of the email notification to be sent to the recipients...
    CREATE OR REPLACE PROCEDURE check_reminder AS
    NO number;
    CURSOR emp_cur is
    select * from pergerakan_ks where TASK_FLAG=7 and TASK_STATUS='InProgress';
    emp_rec emp_cur%rowtype;
    email_to varchar2(200);
    default_email varchar2(200);
    mesg varchar2(4000);
    no_kes varchar2(100);
    subj varchar2(4000);
    kpi number;
    crlf VARCHAR2( 2 ):= CHR( 13 ) || CHR( 10 );
    BEGIN
    default_email:='@abc.com.my';
    FOR emp_rec in emp_cur
    LOOP
    if emp_rec.PKS_TKH_TERIMA is null then
    dbms_output.put_line('count day ' || round(sysdate - to_date(emp_rec.pks_tkh_hantar)) || crlf || crlf);
    if round(sysdate - to_date(emp_rec.pks_tkh_hantar)) >3 then
    email_to:=emp_rec.pks_penghantar_id||default_email;
    select b.KS_BIL_NO into no_kes from kertas_siasatan b where b.KS_ID = emp_rec.pks_ks_id;
    subj:='Reminder untuk Membuat Tindakan Bagi No Kes '||no_kes;
    mesg:='Reminder untuk Membuat Tindakan Bagi No Kes '||no_kes;
    dbms_output.put_line('Sending email to ' || email_to || ' subject: ' || subj);
    dbms_output.put_line('update old pergerakan pks_id : '||emp_rec.pks_id);
    update pergerakan_ks set task_status='Done' where pks_id=emp_rec.pks_id;
    dbms_output.put_line('insert new pergerakan ks : ');
    insert into pergerakan_ks(pks_id,pks_ks_id,pks_km_id,pks_penghantar_id,pks_tkh_hantar,
    pks_penerima_id,pks_tkh_terima,task_name,task_owner,task_status,task_flag,fb_id)
    values(pks_id_seq.nextval,emp_rec.pks_ks_id,emp_rec.pks_km_id,
    emp_rec.pks_penghantar_id,sysdate,
    null,
    null,emp_rec.task_name,
    emp_rec.pks_penghantar_id,
    'InProgress',6,emp_rec.fb_id);
    commit;
    e_mail_message(email_to,email_to,subj,mesg);
    end if;
    end if;
    if emp_rec.PKS_TKH_TERIMA is not null then
    dbms_output.put_line('emp_rec.pks_km_id ' || emp_rec.pks_km_id || crlf);
    select c.KM_KPI into kpi from keluar_masuk_ks c where c.KM_ID = emp_rec.pks_km_id;
    no := round(sysdate - to_date(emp_rec.pks_tkh_terima))-kpi;
    dbms_output.put_line('count day - kpi' || no || crlf);
    dbms_output.put_line('kpi ' || kpi || crlf);
    if no = 1 then
    email_to:=emp_rec.pks_penghantar_id||default_email;
    select b.KS_BIL_NO into no_kes from kertas_siasatan b where b.KS_ID = emp_rec.pks_ks_id;
    subj:='Reminder untuk Membuat Tindakan Bagi No Kes '||no_kes;
    mesg:='Reminder untuk Membuat Tindakan Bagi No Kes '||no_kes;
    dbms_output.put_line('Sending email to ' || email_to || ' subject: ' || subj);
    email_to:=emp_rec.task_owner||default_email;
    subj:='Reminder untuk Membuat Tindakan Bagi No Kes '||no_kes;
    mesg:='Reminder untuk Membuat Tindakan Bagi No Kes '||no_kes;
    dbms_output.put_line('Sending email to ' || email_to || ' subject: ' || subj);
    e_mail_message(email_to,email_to,subj,mesg);
    e_mail_message(email_to,email_to,subj,mesg);
    end if;
    if no = 3 then
    select b.KS_BIL_NO into no_kes from kertas_siasatan b where b.KS_ID = emp_rec.pks_ks_id;
    email_to:=emp_rec.task_owner||default_email;
    subj:='Reminder untuk Membuat Tindakan Bagi No Kes '||no_kes;
    mesg:='Reminder untuk Membuat Tindakan Bagi No Kes '||no_kes;
    dbms_output.put_line('Sending email to ' || email_to || ' subject: ' || subj);
    e_mail_message(email_to,email_to,subj,mesg);
    end if;
    end if;
    END LOOP;
    END;
    E_mail_message is the stored procedure invoked by the check_reminder to tell scheduler information of the connection and the email address of the recipients...
    CREATE OR REPLACE procedure
    e_mail_message
    from_name in varchar2,
    to_name in varchar2,
    subject in varchar2,
    message in varchar2
    is
    l_mailhost VARCHAR2(64);
    l_from VARCHAR2(64);
    l_to VARCHAR2(64);
    crlf VARCHAR2( 2 ):= CHR( 13 ) || CHR( 10 );
    l_mail_conn UTL_SMTP.connection;
    mesg VARCHAR2( 4000 );
    BEGIN
    select a.SERVER into l_mailhost from email_setting a where a.SERVER is not null;
    select a.USERNAME into l_from from email_setting a where a.SERVER is not null;
    --UTL_SMTP.open_data(l_mail_conn);
    mesg:= 'Date: ' || TO_CHAR( SYSDATE, 'dd Mon yy hh24:mi:ss' ) || crlf ||
    'From: <'||l_from||'>' || crlf ||
    'Subject: ' ||subject|| crlf ||
    'To: '||to_name || crlf || '' || crlf ;
    mesg:=mesg||message;
    l_mail_conn := UTL_SMTP.open_connection(l_mailhost, 25);
    UTL_SMTP.helo(l_mail_conn, l_mailhost);
    UTL_SMTP.mail(l_mail_conn, l_from);
    UTL_SMTP.rcpt(l_mail_conn, to_name);
    UTL_SMTP.data(l_mail_conn, mesg);
    UTL_SMTP.quit(l_mail_conn);
    END;
    I tried to execute to execute the e_mail_message procedure but received this error. Also, no notification sent to the email address...
    ORA-29279: SMTP permanent error: 501 5.1.3 Invalid address
    ORA-06512: at "SYS.UTL_SMTP", line 21
    ORA-06512: at "SYS.UTL_SMTP", line 99
    ORA-06512: at "SYS.UTL_SMTP", line 241
    ORA-06512: at "ILMS.E_MAIL_MESSAGE", line 33
    ORA-06512: at line 13
    Please help so that I can receive the email notification into my email...thanks in advance for your time..

    user13281540 wrote:
    ORA-29279: SMTP permanent error: 501 5.1.3 Invalid address
    ORA-06512: at "SYS.UTL_SMTP", line 21
    ORA-06512: at "SYS.UTL_SMTP", line 99
    ORA-06512: at "SYS.UTL_SMTP", line 241
    ORA-06512: at "ILMS.E_MAIL_MESSAGE", line 33
    ORA-06512: at line 13This is not an Oracle error - this is the mail server saying "+hey, I don't like that e-mail address you are supplying, I'm not accepting it!+".
    If you look at RFC821 (Request For Comments memo 821 describes the SMTP specifications), you'll see that the sender and recipient needs to be supplied in the format +<[email protected]>+, e.g. +<[email protected]>+.
    I have found that not all SMTP servers are equal in this regard. Some may insist on the brackets around the address, some may not.
    You need to confirm the format of the addresses you use in the "+MAIL FROM+" and "+RCPT TO+" commands.. and ensure that these formats are accepted by your SMTP server - and if not, change your code to use an acceptable format.
    The easiest way to do this is using telnet - and interacting directly and manually with the server. SMTP is a clear text protocol and easy to use manually. Try it. It is the best way to test SMTP interaction and validate the approach and SMTP commands and arguments used by your code.

  • Send email from the server

    I need to send email from the database.
    Two ways that I am familiar with -
    1. using VB/ODBC controls;
    2. dbms_pipe
    Anyone knows a more 'direct' solution?
    Regards
    Anatoliy Smirnov
    null

    by the way how can u send attchments with mails from database.
    chetan
    try this...(thanks for the subject line help)
    the first message line will be read by non MIME compliant readers, the second message line with be in the body of the note, the nest 2 (third and fourth) will come in as attachments ( text ). Change the Content-type for things like word docs or other 8bit docs (Content-type: application/msword) and write_raw_data for the 8Bit parts
    CREATE OR REPLACE PROCEDURE send_mail_test (sender IN VARCHAR2,
    recipient IN VARCHAR2, subject IN VARCHAR2,
    message IN VARCHAR2)
    IS
    mailhost VARCHAR2(30) := 'smtp.naxs.net';
    mail_conn utl_smtp.connection;
    cv_cCRLF VARCHAR2(10) := UTL_TCP.CRLF;
    lv_message varchar2(4000);
    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,'From: ' | | sender | | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'To: ' | | recipient | | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'Subject:' | | subject | | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'MIME-Version: 1.0' | | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'Content-Type: multipart/mixed; ');
    utl_smtp.write_data(mail_conn,'boundary="NextPart_000_01C002D3.EB460626"' | | cv_cCRLF);
    utl_smtp.write_data(mail_conn, cv_cCRLF | | message| |' first mess part'| | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'--NextPart_000_01C002D3.EB460626' | | cv_cCRLF);
    utl_smtp.write_data(mail_conn, cv_cCRLF | | message| | ' second mess part'| | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'--NextPart_000_01C002D3.EB460626' | | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'Content-Type: text/plain; charset=us-ascii'| | cv_cCRLF);
    utl_smtp.write_data(mail_conn, cv_cCRLF | | message| | ' third mess part'| |cv_cCRLF);
    utl_smtp.write_data(mail_conn,'--NextPart_000_01C002D3.EB460626' | | cv_cCRLF);
    utl_smtp.write_data(mail_conn,'Content-Type: text/plain; charset=us-ascii'| | cv_cCRLF);
    utl_smtp.write_data(mail_conn, cv_cCRLF | | message| | ' fourth mess part'| |cv_cCRLF);
    utl_smtp.write_data(mail_conn,'--NextPart_000_01C002D3.EB460626--' | | cv_cCRLF);
    utl_smtp.close_data(mail_conn);
    -- utl_smtp.data(mail_conn, message);
    utl_smtp.quit(mail_conn);
    EXCEPTION
    WHEN OTHERS
    THEN
    DECLARE
    error_code NUMBER := SQLCODE;
    error_msg VARCHAR2(2000) := SQLERRM;
    error_info VARCHAR2(30);
    BEGIN
    DBMS_OUTPUT.PUT_LINE('We have an error: '| |error_code| |' '| |error_msg);
    END;
    END;
    show errors;
    null

Maybe you are looking for

  • Problem with Flash in Chrome

    Recently my Flash has been acting generally weird. I cannot view certain flash videos, although youtube works, and Flash is not allowing me to set websites store data, making it impossible to use many flash-dependent websites. When I attempt to fix t

  • Chooser problem with HP PSC 1410 and HP Deskjet 5940 on Classic

    Excuse me for my bad english, I am french... !!! I have just bought macmini with HP DeskJet 5940 promotion. I installed internet last driver for it. Printing is OK with Mac OS 10.4.4 but doesn't work with Classic. Printer is connected by USB port. I

  • Report in Transaction CJE0 - LOAD_PROGRAM_NOT_FOUND

    Hi ABAP Gurus, After double clicking a project report in Transaction CJE0, Dump LOAD_PROGRAM_NOT_FOUND occurs.  Can you kindly provide advise on how to check this?  Thank you. Best regards. Brando

  • Exs24 in Logic Express, loading 3d party samples

    Does anyone know if its possible to load sample libraries in exs other then those included in the box?? Or is it restricted to enclosed libraries??

  • Update to 10.8.4 asks reboot after reboot

    I run a MBP 13" on 10.8.3 and tried to update to 10.8.4 yesterday. The App Store download seemed to stop after ca. 10% but with no error message and just asked me for the expected reboot. So I did the reboot, the Mac comes back fine but surprisingly