Introduction
Using below code we can send individual emails to the users with an ICS file as attachment.
ICS is a global format for calendar files widely being utilized by various calendar and email programs including Google Calendar, Apple iCal, and Microsoft Outlook. These files enable users to share and publish information directly from their calendars over email or via uploading it to the world wide web.
Steps To Follow
Step1:
Compile the below code
CREATE OR REPLACE FUNCTION ical_events (
p_summary IN VARCHAR2,
p_description IN VARCHAR2,
p_start_date IN DATE,
p_end_date IN DATE
)
RETURN VARCHAR2
AS
lv_desc VARCHAR2 (20000);
lv_summary VARCHAR2 (10000);
lv_dtstart VARCHAR2 (100);
lv_date VARCHAR2 (100);
lv_dtend VARCHAR2 (100);
l_retval VARCHAR2 (32767);
l_lf CHAR (1) := CHR (10);
BEGIN
lv_summary := ‘SUMMARY:’ || p_summary;
lv_date :=
‘DTSTAMP:’
|| TO_CHAR (SYSDATE, ‘RRRR-MM-DD’)
|| ‘T’
|| TO_CHAR (SYSDATE, ‘HH24:MI:SS’);
lv_dtstart :=
‘DTSTART:’
|| TO_CHAR (p_start_date, ‘RRRR-MM-DD’)
|| ‘T’
|| TO_CHAR (p_start_date, ‘HH24:MI:SS’);
lv_dtend :=
‘DTEND:’
|| TO_CHAR (p_end_date, ‘RRRR-MM-DD’)
|| ‘T’
|| TO_CHAR (p_end_date, ‘HH24:MI:SS’);
l_retval :=
‘BEGIN:VCALENDAR
VERSION:2.0
PRODID:-// Oracle Application Express //ENCAL
SCALE:GREGORIAN
BEGIN:VEVENT
‘
|| lv_date
|| CHR (10)
|| lv_dtstart
|| CHR (10)
|| lv_dtend
|| CHR (10)
|| lv_summary
|| CHR (10)
|| lv_desc
|| ‘
SEQUENCE:0
END:VEVENT
END:VCALENDAR’;
DBMS_OUTPUT.put_line (l_retval);
RETURN l_retval;
END ical_events;
Step2:
Use APEX to create the necessary items to collect the following details:
- Start Date
- End Date
- Summary
- Description
Step3:
Execute the below PLSQL process to send email with ICS file
DECLARE
l_id NUMBER;
l_ical_event VARCHAR2 (32767);
l_blob BLOB;
BEGIN
BEGIN
SELECT ical_events (p_summary => :p2_summary,
p_description => :p2_description,
p_start_date => :p2_start_date,
p_end_date => :p2_end_date
)
INTO l_ical_event
FROM DUAL;
END;
BEGIN
l_id :=
apex_mail.send (p_from => ‘notification-noreply@staging.doyensys.com’,
p_to => ‘admin@staging.doyensys.com’,
p_subj => ‘Subject of the Email’,
p_body => ‘BODY’,
p_body_html => ‘HTML – BODY’
);
EXCEPTION WHEN OTHERS THEN
raise_application_error (-20004, ‘Error in sending an Email’ || SQLERRM );
END;
l_blob := UTL_RAW.cast_to_raw (l_ical_event);
–Converting Varchar2 to BLOB content
BEGIN
apex_mail.add_attachment (p_mail_id => l_id,
p_attachment => l_blob,
p_filename => ‘training.ics’,
–Name of the ICS file
p_mime_type => ‘application/hbs-ics’
);
END;
END;
Conclusion
By following above steps we can send individual emails to the users with an ICS file as attachment.