How to send e-mail from the Java HTML Editor in Oracle Forms including all images and formatting

Now you can send mail directly from the Sferyx Java HTML Editor in your Oracle Form using the editor for composing the message - you can paste, import, drag&drop images or docx, rtf files inside and send it instantly as an e-mail as follows using the method sendEntireContentAsEmailMessage(String host, int port, String fromAddress, String toAddress, String subject):

DECLARE
hArgs FBEAN.ARGLIST;
BEGIN
hArgs := FBEAN.CREATE_ARGLIST;
FBEAN.ADD_ARG(hArgs,'smtp.yourhost.com'); -- SMTP host
FBEAN.ADD_ARG(hArgs,25); --
SMTP port
FBEAN.ADD_ARG(hArgs,'sender@yourhost.com'); -- sender e-mail
FBEAN.ADD_ARG(hArgs,'somebody@somehwere.com'); -- recipient e-mail
FBEAN.ADD_ARG(hArgs,'Message subject'); -- the message subject
FBean.Invoke(bean,1,'sendEntireContentAsEmailMessage',hArgs);

END;

That's all - it is really easy - the e-mail will be sent as Multipart MIME message format and will include the entire formatting and all images included automatically.

New menu items for opening and saving Docx files and saving .eml files:


 

Example screenshot of complex e-mail message created in the Sferyx HTML Editor by importing Microsoft Word .docx file, saved using the export as .eml and opened with Microsoft Outlook:

send mail from java html editor

 

Further, if you need to send e-mails using the Oracle Forms built-in UTL_SMTP API and the editor's API for sending the entire content including all images and formatting as Multipart MIME Message format can be used the sample code below:

DECLARE

bean varchar2(200):='HTMLEDITOR_AREA';
t_id number(20):=1;
hArgs FBEAN.ARGLIST;
parts number(20);
part varchar2(32500);
body_length number(20);
part_size binary_integer := 900;
pos number(20);
last_part_size binary_integer;
p_to VARCHAR2(32500);
p_from VARCHAR2(32500);
p_subject VARCHAR2(32500);
p_smtp_host VARCHAR2(32500);
p_smtp_port NUMBER DEFAULT 25;
l_mail_conn UTL_SMTP.connection;

BEGIN

p_to:='somemail@yourhost.com';
p_from:='sender@yourhost.com';
p_subject:='Test Message';
p_smtp_host:='smtp.yourhost.com';

l_mail_conn := UTL_SMTP.open_connection(p_smtp_host, p_smtp_port);
UTL_SMTP.helo(l_mail_conn, p_smtp_host);
UTL_SMTP.mail(l_mail_conn, p_from);
UTL_SMTP.rcpt(l_mail_conn, p_to);
UTL_SMTP.open_data(l_mail_conn);
UTL_SMTP.write_data(l_mail_conn, 'Date: ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH24:MI:SS') || CHR(13)||CHR(10));
UTL_SMTP.write_data(l_mail_conn, 'To: ' || p_to || CHR(13)||CHR(10));
UTL_SMTP.write_data(l_mail_conn, 'From: ' || p_from || CHR(13)||CHR(10));
UTL_SMTP.write_data(l_mail_conn, 'Subject: ' || p_subject || CHR(13)||CHR(10));

hArgs := FBEAN.CREATE_ARGLIST;
body_length := FBean.Invoke_num(bean,1,'getMultipartMimeMessageContentLength');
parts := trunc(body_length / part_size);
-- Complete parts
if parts > 0 then
for i in 1..parts loop
hArgs := FBEAN.CREATE_ARGLIST;
pos := ((i-1)*part_size);
fbean.add_arg(hargs,pos);
fbean.add_arg(hargs,part_size);
part := fbean.invoke_char(bean,1,'getMultipartMimeMessageContentPortion',hargs);
UTL_SMTP.write_data(l_mail_conn,part);
end loop;
-- Last part
hArgs := FBEAN.CREATE_ARGLIST;
pos := pos + part_size;
last_part_size := body_length - (parts) * part_size;
fbean.add_arg(hargs,pos);
fbean.add_arg(hargs,last_part_size);
part := fbean.invoke_char(bean,1,'getMultipartMimeMessageContentPortion',hargs);
UTL_SMTP.write_data(l_mail_conn,part);
else
hArgs := FBEAN.CREATE_ARGLIST;
fbean.add_arg(hargs,0);
fbean.add_arg(hargs,body_length);
part := fbean.invoke_char(bean,1,'getMultipartMimeMessageContentPortion',hargs);
UTL_SMTP.write_data(l_mail_conn,part);
end if;
UTL_SMTP.close_data(l_mail_conn);
UTL_SMTP.quit(l_mail_conn);
COMMIT;
END;