Highlighted
Absent Member.
Absent Member.
2607 views

[archive] Email attachments using MS CDO?

[Migrated content. Thread originally posted on 28 May 2003]

Thanks to Gisle Forseth for that excellent sample program using MS CDO to send email! Doesn't get any easier than that. I would like to send an attachment with this email method, but I am having trouble. I tried putting this code in right after the MODIFY NEW-MAIL statement:

MODIFY NEW-MAIL @AttachFile
("c:\requests.pdf",
"requests.pdf").

I am now getting the following error message when I run my program:

"Class is not licensed for use"

Has anyone tried sending attachments using Gisle's code?
0 Likes
13 Replies
Highlighted
Absent Member.
Absent Member.

RE: [archive] Email attachments using MS CDO?

Your problem is that albeit CDO is installed, there is no license to use it.
To be honest, I am not quite sure how to obtain a CDO license, I would sort of anticipate it to be the using a normal Outlook license, but I am not quite sure.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Email attachments using MS CDO?

Since there has been so many questions about sending email with attachment, I have decided to post code that does this using COM technology, that is, the ole mapi control. Sorry for the loss of formatting. To use this code, you will have to a) create msmapi32.def using axdefgen, selecting libraries tab and Microsoft Mapi Controls. Name output file msmapi32.def. b) modify John Doe and jdoe@doe.com to be the name of your target. Compile, run and voila!

Note that DISPLAY LABELs are for documentation only, feel free to remove those.

Enjoy.

IDENTIFICATION DIVISION.

PROGRAM-ID. OLEMAPI.
ENVIRONMENT DIVISION.
*====================
*
* Copyright (c) 1996-2001 by Acucorp, Inc. Users of ACUCOBOL
* may freely modify and redistribute this program.
*
* This sample demonstrates how to use the Microsoft MAPI OLE Library
* from ACUCOBOL-GT to send emails.
* Note that this example application requires the use of the attached
* definition file, using another definition file for the MAPI object
* may cause the application to fail.
*
* This technique should work with both OutLook and OutLook Express,
* however, there are some requirements. Take a look at these URLs
* if you experience any problems (urls valid as of 14 November 2001)
* http://support.microsoft.com/support/kb/articles/q180/5/05.asp
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mapi98/html/vbobjmapis.asp
*
* For an overview of the OLE MAPI object:
* http://msdn.microsoft.com/library/default.asp?url=/library/en-us/mapi98/dt_vbobjMAPIS_C.asp
*
* This sample is provided by Acucorp, Inc. 'as is',
*
*
*====================
SPECIAL-NAMES.
COPY "MSMAPI32.DEF".
.
WORKING-STORAGE SECTION.

77 MYSESSION HANDLE OF MAPISESSION OF MSMAPI.
77 MYMESSAGE HANDLE OF MAPIMESSAGES OF MSMAPI.
77 MYSESSID PIC S9(9) COMP-5.
77 CNTL-FONT USAGE HANDLE OF FONT SMALL-FONT.
77 MY-RECIP-NAME PIC X(255) VALUE SPACE.
77 MY-RECIP-ADDR PIC X(255) VALUE SPACE.

PROCEDURE DIVISION.

MAIN-LOGIC.

DISPLAY STANDARD GRAPHICAL WINDOW
LINES 16
SIZE 30
BACKGROUND-LOW
CONTROL FONT IS CNTL-FONT
CELL HEIGHT 12
CELL WIDTH 12
TITLE
"Microsoft OLE MAPI demonstration".

MOVE "John Doe" TO MY-RECIP-NAME.
MOVE "jdoe@doe.com" TO MY-RECIP-ADDR.

IF MY-RECIP-NAME = SPACE
OR MY-RECIP-ADDR = SPACE
INSPECT MY-RECIP-NAME REPLACING TRAILING
SPACES BY LOW-VALUES
INSPECT MY-RECIP-ADDR REPLACING TRAILING
SPACES BY LOW-VALUES
DISPLAY MESSAGE BOX
"Recipient name and/or address must be set "
X"0A"
"Prior to using this software."
X"0A"
"Please adjust your code and recompile."
X"0A"
X"0A"
"Current name: "
MY-RECIP-NAME
X"0A"
"Current address: "
MY-RECIP-ADDR
TITLE "Incomplete address"
GO TO MAIN-LOGIC-END.


DISPLAY LABEL "Creating the session control..." AT 0101.
CREATE MAPISESSION OF MSMAPI
LICENSE-KEY "mgkgtgnnmnmninigthkgogggvmkhinjggnvm"
HANDLE IN MYSESSION.

DISPLAY LABEL "Creating the message control..." AT 0201.
CREATE MAPIMESSAGES OF MSMAPI
LICENSE-KEY "mgkgtgnnmnmninigthkgogggvmkhinjggnvm"
HANDLE IN MYMESSAGE.

DISPLAY LABEL "Disabling mail download..." AT 0301.
MODIFY MYSESSION DOWNLOADMAIL 0.

DISPLAY LABEL
"Logon the mail engine, using default profile..."
AT 0401.
MODIFY MYSESSION SIGNON().

DISPLAY LABEL "Obtain the session id..." AT 0501.
INQUIRE MYSESSION SESSIONID MYSESSID.

DISPLAY LABEL
"Associate the message with the current session..."
AT 0601.
MODIFY MYMESSAGE SESSIONID = MYSESSID.

DISPLAY LABEL "Prepare a new message..." AT 0701.
MODIFY MYMESSAGE COMPOSE().

DISPLAY LABEL "Set the message subject..." AT 0801.
MODIFY MYMESSAGE MSGSUBJECT =
"This is the subject".

DISPLAY LABEL "Set the message body text..." AT 0901.
MODIFY MYMESSAGE MSGNOTETEXT =
"Hello world from ACUCOBOL-GT using OLE MAPI".

* If you have multiple files, duplicate the MODIFY statement,
* but increment by one for each additional file, like:
* File 1: ATTACHMENTINDEX = 0 ATTACHMENTPOSITION 0
* File 2: ATTACHMENTINDEX = 1 ATTACHMENTPOSITION 1
* and so on

DISPLAY LABEL "Sending an attachment..." AT 1001.
MODIFY MYMESSAGE ATTACHMENTINDEX = 0
ATTACHMENTPOSITION = 0
ATTACHMENTPATHNAME =
"olemapi.cbl".

DISPLAY LABEL "Set recipient 'real' name..." AT 1101.
MODIFY MYMESSAGE RECIPDISPLAYNAME =
MY-RECIP-NAME.

DISPLAY LABEL "Set recipient email address..." AT 1201.
MODIFY MYMESSAGE RECIPADDRESS =
MY-RECIP-ADDR.

DISPLAY LABEL "Send message, no verification dialog..."
AT 1301.
MODIFY MYMESSAGE SEND(0).

DISPLAY LABEL "Log off session..." AT 1401.
MODIFY MYSESSION SIGNOFF().

DISPLAY LABEL "Email transmit done..." AT 1501.
ACCEPT OMITTED AT 1523.

* Clean up
DESTROY MYMESSAGE.
DESTROY MYSESSION.


MAIN-LOGIC-END.

STOP RUN.
Highlighted
Absent Member.
Absent Member.

RE: [archive] Email attachments using MS CDO?

I try with axdefgen.exe click on librairies and search for Microsoft Mapi and did not find anything.

Could you help me!
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Email attachments using MS CDO?

Sorry for the late response. I have been out travelling.
If you can't find anything with AxDefGen, that means the component has not been installed. You may download it here:

http://activex.microsoft.com/controls/vb6/msmapi32.cab

Note that this is a cab file, so you would need a cab utility to extract it.

Once extracted, among the content, there should be a file msmapi32.ocx. register this and try again.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Email attachments using MS CDO?

OK, a blast from the past!

Whenever I try to add this to an existing program (or use the sample supplied) I get the following error in the full listing file

00266A MODIFY MYMESSAGE SEND(0).
-->ERROR: Verb expected, '(' found


Any ideas what this means.

Thanks,

Shaun
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Email attachments using MS CDO?

This is correct, SEND conflicts with ACUCOBOL-GT thread verb SEND, thus it has to be prefixed with @ to identify it as related to the ActiveX for the compiler.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Email attachments using MS CDO?

I followed the above post, compiles clean, and runs clean, but doesn't send any email....where can I look to see what else needs to be done.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Email attachments using MS CDO?

Beats me, do you have a reproduceable?
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Email attachments using MS CDO?

attached is the compiled code see if it does the same for you.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Email attachments using MS CDO?

Originally posted by ryanneves
attached is the compiled code see if it does the same for you.


I am sorry, I don't do anything with this. If you want me to look at it, I need source.
0 Likes
Highlighted
Absent Member.
Absent Member.

RE: [archive] Email attachments using MS CDO?

I sent the object simply to see if you're system gets the same reaction, here is the source.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.