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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Interfacing with MS Outlook to create an email

Status
Not open for further replies.

tsheps

Programmer
Feb 7, 2005
2
ZA
Hi,

Being relatively new in the Acucobol field, I need help in creating an email with an attachment using the Windows MAPI. I run the Acucorp Version 6.1 Compiler on a Windows 2000 box.
I came across the following code to create the mail item:

WORKING STORAGE
01 w01-attach pic x(15) value "\attach.html".
77 outlook-handle handle of application.
77 mail-handle handle of mailitem.
77 namespc-handle handle of NameSpace.
...
create application of Outlook handle in outlook-handle
modify outlook-Handle, @GetNameSpace("MAPI")
giving namespc-handle
...
modify Outlook-Handle, createitem (olMailItem) giving
mail-handle
modify mail-handle @subject ws-subj
modify mail-handle @body ws-body-tab
modify mail-handle @To ws-to
modify mail-handle @cc ws-cc

The above successfully creates the mail item and sets up the email address, subject etc.

My problem is in an attempt to append an attachment to this mail item!
I've tried the following (and others!) to no avail...

modify mail-handle @Attachments w01-attach

...didn't work. Got this error: 'ATTACHMENTS' must be a 'put' property or method of '@MAILITEM'

Please help!





 
You need to create the Attachments object. I haven't done it with COBOL, but here is a VB example. Look at the boldened lines.
Code:
        ' Create a new MailItem.
        [b]Dim oMsg As Outlook._MailItem[/b]
        oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
        oMsg.Subject = "Send Attachment Using OOM in Visual Basic .NET"
        oMsg.Body = "Hello World" & vbCr & vbCr

        oMsg.To = "user@example.com"

        ' Add an attachment
        Dim sSource As String = "C:\Temp\Hello.txt"
        Dim sDisplayName As String = "Hello.txt"

        Dim sBodyLen As String = oMsg.Body.Length
        [b]Dim oAttachs As Outlook.Attachments = oMsg.Attachments
        Dim oAttach As Outlook.Attachment[/b]
        oAttach = oAttachs.Add(sSource, , sBodyLen + 1, sDisplayName)

        oMsg.Send()

__________________________________________
Try forum1391 for lively discussions
 
Thanks for your help Dimandja.
After a couple of days of experimenting, a colleague of mine found that the problem with my initial code was the use of the verb 'MODIFY' to create the link. The correct verb to use is 'INQUIRE' ...!!

The working code is:

WORKING-STORAGE.
77 attach-handle handle of Attachments.
...
modify Outlook-Handle, createitem (olMailItem) giving
mail-handle
modify mail-handle @subject ws-subj
modify mail-handle @body ws-body-tab
modify mail-handle @To ws-to
modify mail-handle @cc ws-cc

inquire mail-handle @Attachments attach-handle
modify attach-handle @Add(w01-attach)


modify mail-handle @send()
 
Cool.

__________________________________________
Try forum1391 for lively discussions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top