使用oracle apex 4.2.5和utl_smtp不支持日历消息

时间:2014-09-15 13:59:22

标签: oracle outlook oracle-apex

我一直在尝试使用Dan的博客尝试通过电子邮件发送iCalendar活动 http://www.danielmcghan.us/2008/06/icalendar-event-via-email.html

我没有在outlook 2007中预览,只是附件 不支持日历message.ics

虽然附件成功创建了日历条目。

以下是一个示例文件:https://db.tt/tCOtafyO

这就是我发送日历事件的方式:

if (P_OUTLOOK)
    then
       l_ical_event := hrm_ical_event(
         -- p_start_date      => to_date( '16-09-2014 09:00:00' , 'dd-mm-yyyy HH24:MI:SS') --TO_DATE(l_startdatum || l_starttijd,'DD-MM-YYYY HH24:MI:SS') --HH:MIPM')
        --, p_end_date        => to_date( '16-09-2014 16:30:00' , 'dd-mm-yyyy hh24:mi:ss') --TO_DATE(l_einddatum || l_eindtijd,'DD-MM-YYYY HH24:MI:SS') --HH:MIPM')
         p_start_date      =>TO_DATE(trunc(l_startdatum) || ' ' || l_begintijd,'DD-MM-YYYY HH24:MI:SS') --HH:MIPM')
        , p_end_date        => TO_DATE(trunc(l_einddatum) || ' ' || l_eindtijd,'DD-MM-YYYY HH24:MI:SS') --HH:MIPM')
        , p_description  => l_body
        , p_location     => l_locatie
        , p_summary         => l_subj
        , p_organizer_name  => 'HRD'
        , p_organizer_email => p_afzender
       );

       hrm_mail_outlook( 
          p_from        => p_afzender
        , p_to      => p_ontvanger
        , p_subj      =>  l_subj
        , p_body_html => '<font size="2" face="Arial">' || l_body || '</font>'
        , p_body_cal => l_ical_event
       );

这是我的hrm_ical_event:

CREATE OR REPLACE FUNCTION APP_ISI.HRM_ical_event (
   p_summary         IN VARCHAR2   
 , p_organizer_name  IN VARCHAR2   
 , p_organizer_email IN VARCHAR2
 , p_description     IN VARCHAR2   
 , p_start_date      IN DATE  
 , p_end_date        IN DATE
 , p_location        IN VARCHAR2 := NULL  
 , p_version         IN VARCHAR2 := NULL  
 , p_prodid          IN VARCHAR2 := NULL  
 , p_calscale        IN VARCHAR2 := NULL  
 , p_method          IN VARCHAR2 := NULL  
)   

   RETURN VARCHAR2   

AS     

   l_retval VARCHAR2(32767);
   l_lf     CHAR(1) := CHR(10);      

BEGIN  

   l_retval := ''  
      || 'BEGIN:VCALENDAR' || l_lf   
      || 'VERSION:' || NVL(p_version,'2.0') || l_lf   
      || 'PRODID:' || NVL(p_prodid,'-/MN//NONSGML ICAL_EVENT//NL') || l_lf   
      || 'CALSCALE:' || NVL(p_calscale,'GREGORIAN') || l_lf   
      || 'METHOD:' || NVL(p_method,'REQUEST') || l_lf   
      || 'BEGIN:VEVENT' || l_lf   
      || 'SUMMARY:' || p_summary || l_lf
      || 'LOCATION:' || p_location || l_lf         
      || 'ORGANIZER;CN="' || p_organizer_name || '":MAILTO:' || p_organizer_email || l_lf   
      || 'DESCRIPTION:' || p_description || l_lf
      || 'DTSTART:' || TO_CHAR(p_start_date,'YYYYMMDD') || 'T' || TO_CHAR(p_start_date,'HH24MISS') || l_lf   
      || 'DTEND:' || TO_CHAR(p_end_date,'YYYYMMDD') || 'T' || TO_CHAR(p_end_date,'HH24MISS') || l_lf   
      || 'DTSTAMP:' || TO_CHAR(SYSDATE,'YYYYMMDD') || 'T' || TO_CHAR(SYSDATE,'HH24MISS') || l_lf   
      || 'UID:' || RAWTOHEX(SYS_GUID()) || '@mn.nl' || l_lf   
      || 'STATUS:NEEDS-ACTION' ||  l_lf   
      || 'END:VEVENT' || l_lf   
      || 'END:VCALENDAR';   

   RETURN l_retval; 

END hrm_ical_event;
/

这是我的hrm_mail_outlook:

CREATE OR REPLACE PROCEDURE APP_ISI.HRM_MAIL_OUTLOOK
 (p_from         IN  VARCHAR2
    , p_to           IN  VARCHAR2
    , p_subj         IN  VARCHAR2
    , p_body_html    IN  VARCHAR2
    , p_body_cal     IN  VARCHAR2
 )
  IS
      l_connection   UTL_SMTP.CONNECTION;
      l_mail_server  VARCHAR2(255) := 'mail.yourserver.com';
      l_mail_port    PLS_INTEGER := 25;
      l_msg_hrd      VARCHAR2(32767);
      l_msg_body     VARCHAR2(32767);
      l_lf           VARCHAR2(2) := CHR(13)||CHR(10);
      BEGIN

      l_msg_body := '' 
         || 'Date: ' || TO_CHAR(SYSDATE,'DAY, DD-MON-RR HH24:MI') || l_lf 
         || 'From: <' || p_from || '> ' || l_lf 
         || 'Subject: ' || p_subj || l_lf 
         || 'To: ' || p_to || l_lf 
         || 'MIME-Version: 1.0' || l_lf
         || 'Content-type: multipart/mixed; boundary="frontier"' || l_lf
         || '--frontier' || l_lf
         || 'Content-Type: text/calendar' || l_lf
         || 'charset="utf-8"' || l_lf
         || 'method=REQUEST' || l_lf
         || 'component=vevent' || l_lf 
         || l_lf
         || p_body_cal || l_lf
         || '--frontier' || l_lf
         || 'Content-Type: text/html' || l_lf
         || 'charset="utf-8"' || l_lf 
         || l_lf
         || p_body_html || l_lf
         || '--frontier--';

      l_connection := utl_smtp.open_connection(l_mail_server, l_mail_port);
      utl_smtp.helo(l_connection, l_mail_server);
      utl_smtp.mail(l_connection, p_from);
      utl_smtp.rcpt(l_connection, p_to);
      utl_smtp.data(l_connection, l_msg_body);
      utl_smtp.quit(l_connection);

   END HRM_MAIL_OUTLOOK;
/

1 个答案:

答案 0 :(得分:0)

CREATE OR REPLACE FUNCTION APP_ISI.HRM_ical_event (
   p_summary         IN VARCHAR2   
 , p_organizer_name  IN VARCHAR2   
 , p_organizer_email IN VARCHAR2
, p_start_date      IN DATE
, p_end_date        IN DATE
, p_location        in varchar2 := null
, p_description     in varchar2 := null
, p_trigger         IN VARCHAR2 DEFAULT '60M'--(Code defaults to 60 minute warning)
, p_version         IN VARCHAR2 := NULL -- (Code defaults it to 2.0 if null)
, p_prodid          IN VARCHAR2 := NULL -- (Code defaults it to '-//Company Name//NONSGML ICAL_EVENT//EN' if null)
, p_calscale        IN VARCHAR2 := NULL -- (Code defaults it to GREGORIAN if null)
, p_method          IN VARCHAR2 := NULL) -- (Code defaults it to REQUEST if null)
   RETURN VARCHAR2   

AS     

   l_retval VARCHAR2(32767);
   l_lf     CHAR(2) := CHR(13)||CHR(10);     

BEGIN  

   l_retval := ''  
      || 'BEGIN:VCALENDAR' || l_lf
      || 'VERSION:' || NVL(p_version,'2.0') || l_lf
      || 'PRODID:' || NVL(p_prodid,'-//Company Id//NONSGML ICAL_EVENT//EN') || l_lf
      || 'CALSCALE:' || NVL(p_calscale,'GREGORIAN') || l_lf
      || 'METHOD:' || NVL(p_method,'REQUEST') || l_lf
      || 'BEGIN:VEVENT' || l_lf
      || 'SUMMARY:' || p_summary || l_lf
      || 'ORGANIZER;CN="' || p_organizer_name || '":MAILTO:' || p_organizer_email || l_lf
      || 'DTSTART:' || TO_CHAR(p_start_date,'YYYYMMDD') || 'T' || TO_CHAR(p_start_date,'HH24MISS') || l_lf
      || 'DTEND:' || TO_CHAR(p_end_date,'YYYYMMDD') || 'T' || TO_CHAR(p_end_date,'HH24MISS') || l_lf
      || 'LOCATION:' || p_location || l_lf
      || 'DESCRIPTION:' || p_description || l_lf
      || 'DTSTAMP:' || TO_CHAR(SYSDATE,'YYYYMMDD') || 'T' || TO_CHAR(SYSDATE,'HH24MISS') || l_lf
      || 'UID:' || RAWTOHEX(SYS_GUID()) || '@company.com' || l_lf
      || 'STATUS:NEEDS-ACTION' ||  l_lf
      || 'BEGIN:VALARM' || l_lf
      || 'TRIGGER:-PT'||p_trigger|| l_lf
      || 'REPEAT:1' || l_lf
      || 'DURATION:PT60M' || l_lf
      || 'ACTION:DISPLAY' || l_lf
      || 'DESCRIPTION' || p_description || l_lf
      || 'END:VALARM' || l_lf
      || 'END:VEVENT' || l_lf
      || 'END:VCALENDAR';

   RETURN l_retval; 

END hrm_ical_event;