Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
MAPI - Sending Attachments to Recipients Programmaticall
Message
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00261254
Message ID:
00261392
Views:
25
Thanks very much. Looking at your code has helped, but I still have some issues...

1) The e-mail message does not automatically get sent. Instead, my message comes up in Outlook and I have to manually click on "Send" to send it.

2) Even though the recipient name is underlined, like it has been resolved OK, I promptly get mail back from System Administrator stating: Your message did not reach some or all of the intended recipients. The following recipients could not be reached: 'Chuck Henry' on 9/3/99 3:42 PM No transport provider was available for delivery to this recipient.

3) An attachment icon shows up in the message, but there doesn't seem to be a real file there. It does nothing when I double-click on it, or when I right-click it and choose an action from the context menu.

Here is my code as of now...
* Add the MSMAPI.MAPISession and MSMAPI.MAPIMessages OLE controls to this form.
ThisForm.AddObject("Session1","olecontrol","MSMAPI.MAPISession")
ThisForm.AddObject("Message1","olecontrol","MSMAPI.MAPIMessages")

* Call the signon method of the MAPISession control. If the user is not
* logged on to mail, this will prompt the user to logon. This also sets
* the SessionID property for the MAPIsession control.
ThisForm.Session1.SignOn

* Set the SessionId of the MAPIMessage control
* to the SessionId of the MAPISession control, which was just obtained.
ThisForm.Message1.SessionId = ThisForm.Session1.SessionId

* Start an e-mail message
ThisForm.Message1.Compose
* Increment the Recipient index
ThisForm.Message1.RecipIndex = 0
* Set the Recipient Name
ThisForm.Message1.RecipDisplayName = "CHUCK HENRY"
* Resolve the Recipient Name
ThisForm.Message1.ResolveName
* Set the Subject line and Message text
ThisForm.Message1.MsgSubject = "Change Order " + Ord_Ma(2)
ThisForm.Message1.MsgNoteText = "Electronic Change Order Text file for Order Number: " + Ord_Ma(2)
* Attach ChgOrder.txt file
ThisForm.Message1.AttachmentPathname = "ChgOrder.txt"

* Sends the e-mail message. The (1) is requried to send the message.
ThisForm.Message1.Send(1)

* Remove the MSMAPI.MAPISession and MSMAPI.MAPIMessages OLE controls from this form.
ThisForm.RemoveObject("Session1","olecontrol","MSMAPI.MAPISession")
ThisForm.RemoveObject("Message1","olecontrol","MSMAPI.MAPIMessages")
>This is code from a class I have for MAPI stuff. I instantiate the session and message objects in the init of the class like this:
>
>This.oSession = CreateObject('MSMAPI.MAPISession')
>This.oMessage = CreateObject('MSMAPI.MAPIMessages')
>
>Then I have properties for all the parts of a message and programmatically set them before calling a custom Send method. The send method is as follows:
>
>*set step on
>
>WAIT WINDOW NOWAIT "Please wait ... Logging Into Mail"
>
>* Signon to mail
>IF !This.lLoggedIn AND !EMPTY(This.cProfile)
> This.oSession.UserName = This.cProfile
> This.oSession.Signon
> This.lLoggedIn = .T.
>ELSE
> RETURN .F.
>ENDIF
>
>* If the session ID is not valid, do not go any further
>IF This.oSession.SessionID > 0
> This.oMessage.SessionID = This.oSession.SessionID
>ELSE
> WAIT WINDOW NOWAIT "Login Failed"
> RETURN .F.
>ENDIF
>
>* Start a new message
>This.oMessage.Compose
>* Increment the Recipient index
>This.oMessage.RecipIndex = 0
>
>* Set the Recipient name and resolve
>IF EMPTY(This.cSendTo)
> RETURN .F.
>ENDIF
>
>This.oMessage.RecipDisplayName = This.cSendTo
>This.oMessage.ResolveName
>
>IF !EMPTY(This.cSubject)
> This.oMessage.MsgSubject = This.cSubject
>ENDIF
>
>IF !EMPTY(This.cText)
> This.oMessage.MsgNoteText = This.cText
>ENDIF
>
>IF !EMPTY(This.cAttachment)
> This.oMessage.AttachmentPathname = This.cAttachment
>ENDIF
>
>WAIT WINDOW NOWAIT "Sending Message ... "
>
>This.oMessage.Send(0)
>
>WAIT WINDOW NOWAIT "Message Sent!"
>RETURN .T.
>
>You should be able to get the idea from this, if not feel free to write back. If anyone thinks it is useful, let me know and I'll submit the class to UT. The thing I liked about my approach (other than it was mine <g>) was it encapsulated the mechanics of the 2 objects into one ie Message and Session were rolled into one object which is the way I think of MAPI anyway.
>
>"Coles Law: Thinly sliced cabbage"


>This is code from a class I have for MAPI stuff. I instantiate the session and message objects in the init of the class like this:
>
>This.oSession = CreateObject('MSMAPI.MAPISession')
>This.oMessage = CreateObject('MSMAPI.MAPIMessages')
>
>Then I have properties for all the parts of a message and programmatically set them before calling a custom Send method. The send method is as follows:
>
>*set step on
>
>WAIT WINDOW NOWAIT "Please wait ... Logging Into Mail"
>
>* Signon to mail
>IF !This.lLoggedIn AND !EMPTY(This.cProfile)
> This.oSession.UserName = This.cProfile
> This.oSession.Signon
> This.lLoggedIn = .T.
>ELSE
> RETURN .F.
>ENDIF
>
>* If the session ID is not valid, do not go any further
>IF This.oSession.SessionID > 0
> This.oMessage.SessionID = This.oSession.SessionID
>ELSE
> WAIT WINDOW NOWAIT "Login Failed"
> RETURN .F.
>ENDIF
>
>* Start a new message
>This.oMessage.Compose
>* Increment the Recipient index
>This.oMessage.RecipIndex = 0
>
>* Set the Recipient name and resolve
>IF EMPTY(This.cSendTo)
> RETURN .F.
>ENDIF
>
>This.oMessage.RecipDisplayName = This.cSendTo
>This.oMessage.ResolveName
>
>IF !EMPTY(This.cSubject)
> This.oMessage.MsgSubject = This.cSubject
>ENDIF
>
>IF !EMPTY(This.cText)
> This.oMessage.MsgNoteText = This.cText
>ENDIF
>
>IF !EMPTY(This.cAttachment)
> This.oMessage.AttachmentPathname = This.cAttachment
>ENDIF
>
>WAIT WINDOW NOWAIT "Sending Message ... "
>
>This.oMessage.Send(0)
>
>WAIT WINDOW NOWAIT "Message Sent!"
>RETURN .T.
>
>You should be able to get the idea from this, if not feel free to write back. If anyone thinks it is useful, let me know and I'll submit the class to UT. The thing I liked about my approach (other than it was mine <g>) was it encapsulated the mechanics of the 2 objects into one ie Message and Session were rolled into one object which is the way I think of MAPI anyway.
>
>"Coles Law: Thinly sliced cabbage"
Chuck Henry
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform