Skip to Main Content
  • Questions
  • Retrieve email from office 365 cloud Using PL/SQL

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Umair Farhat Mobeen Khan.

Asked: August 18, 2020 - 10:54 am UTC

Last updated: August 27, 2020 - 5:27 am UTC

Version: oracle 11g R2

Viewed 1000+ times

You Asked

Hi Tom,

I have a requirement for connecting to office 365 which is in cloud and open the mailbox, read the email, download it and then insert into database table using PL/SQL Block. How can i achieve this, Please help me.Thank you so much in advance.

and Connor said...

Check out this client

http://plsqlmailclient.sourceforge.net/

That is the closest I've seen to your requirement, but I suspect the level of security to acess Office 365 (SSL etc) might be a problem.

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Mail_client package is not reading my mail from cloud office 365

Umair Farhat Farhat Mobeen Khan, August 23, 2020 - 8:23 am UTC

Hi,

I am migrating my mailbox to office 365 cloud from outlook 2007 on premises . My pl/sql block is not reading email from office365 cloud. same code is working in outlook 2007 which in on premises. i am using Mail_Client API which is working fine when the mailbox is in on premises. After moving to cloud office 365, same pl/sql code is not reading the emails. I have seen same issue is raised by many but no solution for this


connect &1
set define '^'
set verify off
set serveroutput on
set feedback off
set heading off
set colsep ,

prompt Connecting Support Services INBOX, Please wait.........
declare
n number;
begin
--setMaxMemorySize(1024*1024*1024);
select setMaxMemorySize(1024*1024*1024*4) into n from dual;
end;
/

begin
-- KOJ_Open.sql support.service ihelp4koj
mail_client.connect_server(
p_hostname => 'mail.kojamjoom.com',
p_port => 143,
p_protocol => 'imap',
p_userid => 'xyz@kojamjoom.com',
p_passwd => 'xyz@123',
p_ssl => false
);

mail_client.open_inbox;
-- dbms_output.put_line('Mailbox successfully opened.');
dbms_output.put_line('The INBOX folder contains '||mail_client.get_message_count||' messages.');

end;
/
prompt Taking Snapshot of Unread Mails, Please wait.........

begin
-- KOJ_List.sql
mail_filter.clear_filters;
mail_filter.add_seen_filter(false);

execute immediate 'truncate table MAILUSER.KOJ_MAIL_HEADER_TEMP';
COMMIT;
INSERT INTO MAILUSER.KOJ_MAIL_HEADER_TEMP
(MAIL_ID,MSG_NUMBER, SENDER, SENT_DATE, SUBJECT, SENDER_EMAIL, CONTENT_TYPE, MESSAGE_SIZE,READ, ANSWERED, DELETED,RECENT,STATUS,TYPE)
SELECT MAILUSER.MAIL_ID_SEQ.NEXTVAL,MSG_NUMBER,SENDER,SENT_DATE,SUBJECT, SENDER_EMAIL, CONTENT_TYPE, MESSAGE_SIZE,READ,ANSWERED,DELETED,RECENT,'OPEN','INC' FROM TABLE(MAIL_CLIENT.GET_MAIL_HEADERS());
INSERT INTO MAILUSER.KOJ_MAIL_HEADER SELECT * FROM MAILUSER.KOJ_MAIL_HEADER_TEMP;
commit;
end;
/
prompt Downloading INBOX, Please wait.........
begin
--Call KOJ_Image_MultiAttach_and_text and koj_extract_mail
--setMaxMemorySize(1024*1024*1024*1024);
KOJ_readmail_download;
end;
/
prompt Download completed Successfully.
begin
--KOJ_Close.sql
mail_client.close_folder;
mail_client.disconnect_server;
end;
/
prompt Updating HD Tables and COW Tables
--@KOJ_HD_UpdateTIckets.sql
--@KOJ_HD_UpdateTIcketsMail.sql
--@KOJ_HD_AutoRoute_UpdateTIcketsMail.sql
--@KOJ_HD_AutoRoute_UpdateTIcketsMailUpd.sql
@KOJ_HD_AutoRoute_UpdateTIcketsMailShpUpd.sql
--prompt Mailing to Call Center
--@KOJ_HD_Mail2CC.sql
prompt Checking and Updating Pending SD+ Mails
--@KOJ_HD_PendingMailCheckup.sql
@KOJ_HD_PendingMailCheckupShpUpd.sql
prompt Checking for COW Pending Mails
@KOJ_HD_PendingCOWCheckup.sql
exit;
.


Error
ORA-29532 Java call terminated by uncaught java exception
javax.mail_client.authenticationFailedException: Login failed

Connor McDonald
August 27, 2020 - 5:27 am UTC

I'd very surprised if you can read a non-local email without using SSL.

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library