[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

Manipulate exchange in code

i want to code the proccess of opening exchange, creating a new message and attaching a specified file to the message.
how do i do that?

1 Solution
This is a great program that will do this for you:

Private Sub sendwitham()
Dim osession As Object
Dim omessage As Message

On Error Resume Next
Set osession = CreateObject("mapi.session")
If osession Is Nothing Then
Exit Sub
End If
'If Err Then Exit Sub
Set omessage = osession.Outbox.Messages.Add
With omessage
Subject = txtsubject 'this is a textbox on your form, you can hard code this too eg "birthday"

Text = " " & txtnotetxt' same as above can be hardcoded same way
End With

With omessage.Recipients.Add
Name = txtname'please note this is a text box, you can hard code this eg "JONdoe@aol.com"

Type = mapiTo
End With
If Len(txtattach) Then 'txtattach is a textbox that has the full path and name of the file to attach can be hardcoded "c:\autoexecbat", but remember to change ALL references to TXTATTACH.
With omessage.Attachments.Add
Position = 1
Type = mapiFileData
Name = txtattach
ReadFromFile txtattach
End With
End If
MsgBox ("DONE")'optional

End Sub

Private Sub Command1_Click()

End Sub

ynyAuthor Commented:
I am familiar with this kind of solution but its not enough.
i want to open the exchange itself,so the user would be able to locate an address in the address list & send the message to few Recipients, without knowing theire addresses in advance.
Hi! ymy, I think the following code should solve yur problem. It will open your mail utility( exchange etc) and give you all the options thereafter.

I have added the foolowing code on the click of a button:

Private Sub Command1_Click()
Dim objSession As Object    ' Session object
Dim objMessage As Object     ' Message object

On Error GoTo error_olemsg
 ' create a session then log on, supplying username and password
 Set objSession = CreateObject("MAPI.Session")

 ' change the parameters to valid values for your configuration

 ' create a message and fill in its properties
 Set objMessage = objSession.Outbox.Messages.Add

' the following line is important because it will open your mail ' utility
objMessage.Send True, True, 0 '(savecopy,showdialog,parentwindow)

    Exit Sub
    'MsgBox "Error " & Str(Err) & ": " & Error$(Err)
    Exit Sub

End Sub


Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now