Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send e-mail with attachment

Status
Not open for further replies.

JeanneZ

Programmer
Joined
May 1, 2003
Messages
55
Location
US
Hi, Oracle experts,

I have some questions for sending e-mail with attachment files.
I have read “Ask Tom” about this topic from:


I am not Java expert and never used Java in Oracle. So I just followed step by step to download JavaMail API. But I do not have SYS userid and password and I sent that java files to our DBA and asked him to load them for me. After he told me it was ready, I copied java source “mail” which Tom provided. My questions are:

1. How can I compile the code? After I copied the code and tried to compile it, I got error:
create or replace and compile java source named "mail"
*
ERROR at line 1:
ORA-29536: badly formed source: User has attempted to load a class
(mail$BLOBDataSource) into a restricted package. Permission can be granted
using dbms_java.grant_permission(<user>, LoadClassInPackage...

Is that mean DBA should grant permission to me for using java package? What is command to grant?

2. Should the attachment files must be text file? Can I attach PDF files? What’s mean about dftMime = &quot;application/octet-stream&quot; inside java class mail code? What directory is for the attachment files? Can I put the files in my local directory or must be in database directory?

Thanks in advance

Jeanne
 
Hi
Here is one example of using the OLE2 built-in to
send an email with an attachment.

Regards
Himanshu

The code below runs from a command button on a Form
(when button pressed trigger):



DECLARE


OutlookApp OLE2.OBJ_TYPE;
NameSpace OLE2.OBJ_TYPE;
MailItem OLE2.OBJ_TYPE;
OLEPARAM OLE2.LIST_TYPE;
Send OLE2.OBJ_TYPE;
Attachments OLE2.OBJ_TYPE;
Attachment_dummy OLE2.OBJ_TYPE;
var1 varchar2(100);


Begin

--assign a value to the variable from the Oracle Form
-- var1 := :BLOCK5.txt5;

--but for testing, populate the variable 'by hand'
var1 := 'This is a test of Outlook from Oracle app.';

OutlookApp := OLE2.CREATE_OBJ('Outlook.Application');


OLEPARAM := OLE2.CREATE_ARGLIST;


OLE2.ADD_ARG(OLEPARAM,'MAPI');
NameSpace := OLE2.INVOKE_OBJ(OutlookApp,'GetNameSpace',OLEPARAM);
OLE2.DESTROY_ARGLIST(OLEPARAM);


OLEPARAM := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(OLEPARAM,0);
MailItem := OLE2.INVOKE_OBJ(OutlookApp,'CreateItem',OLEPARAM);
OLE2.DESTROY_ARGLIST(OLEPARAM);


OLE2.SET_PROPERTY(MailItem,'To','himan_bharadwaj@hotmail.com');
OLE2.SET_PROPERTY(MailItem,'Subject','message testing Outlook
automation from Oracle');
OLE2.SET_PROPERTY(MailItem,'Body', 'hello again '||var1);


--add an attachment
Attachments := OLE2.GET_OBJ_PROPERTY(MailItem,'Attachments');
OLEPARAM := OLE2.CREATE_ARGLIST;
OLE2.ADD_ARG(OLEPARAM,'C:\chris_school.txt');
Attachment_dummy := OLE2.INVOKE_OBJ(Attachments,'add',OLEPARAM);
OLE2.DESTROY_ARGLIST(OLEPARAM);


Send := OLE2.INVOKE_OBJ(MailItem,'Send');


--destroy objects
OLE2.RELEASE_OBJ(MailItem);
OLE2.RELEASE_OBJ(NameSpace);
OLE2.RELEASE_OBJ(OutlookApp);


END;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top