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

Is this possible????

Status
Not open for further replies.

enak

Programmer
Jul 2, 2002
412
US
I have been trying to find out if I can create an Outlook appointment and send it to multiple addresses.

I want to do this with ASP.NET but I can move to ASP and COM if I need to.

Also, we are using Exchange 2000.

What I know so far is that I can only use Exchange 2003 with .NET. The appointment will be created and sent from the server so I don't want anything to HANG the server.

If I have to I can call an ASP from the ASPX which could access a COM object. I think that this would be done using CDO or CDOEX. However, I would rather keep it in .NET if it is at all possible.

Thanks
enak
 
You can add a COM reference in .NET and it will create what's called a "Runtime Callable Wrapper" for the object. You may then interact with the COM object from your .NET classes.

Native .NET objects are, of course, faster than RCWs, but RCWs are currently just a part of the game. Office 2003 is still COM based, in fact.

Anyway, what I'm getting at is that you should have no problem using CDO in .NET. I'm not super skilled with the interop, but I have made classes that manipulated appointments via a DataGrid, so I know it's do-able.
 
I don't know if this will help any, but I have code I wrote for a VB.NET Windows Service that parse through a MS Outlook Inbox. Maybe you can take concepts from this and apply them to appointments.

Code:
    Sub RunThroughInbox(ByVal sender As Object, _
                            ByVal e As ElapsedEventArgs) _
                            Handles cbInboxTimer.Elapsed
        Try
            If profile.RunService Then
                If profile.WriteServiceRunningMessageToLog Then
                    EventLog.WriteEntry("NECSInBox", profile.GetServiceRunningMessage)
                End If

                Dim olApp As Outlook.Application = New Outlook.Application
                Dim olNS As Outlook.NameSpace = olApp.GetNamespace("MAPI")
                olNS.Logon(profile.GetDefaultMailProfile, Missing.Value, False, True)

                Dim olIn As Outlook.MAPIFolder = olNS.Folders.Item(profile.GetNecsMailbox)
                Dim olInbox As Outlook.MAPIFolder = olIn.Folders.Item(profile.GetNecsMailboxInbox)

                Dim olItems As Outlook.Items = olInbox.Items
                Dim boxCount As Integer = olItems.Count
                Dim i As Integer
                Dim cnt As Integer = 0
                Dim delKey As Integer
                '********************
                'Dim strMessage As String
                '********************

                Try

                    For i = boxCount To 1 Step -1

                        Dim err As String = ""
                        Dim keyIndexSubject As String = String.Empty
                        Dim keyIndexBody As String = String.Empty
                        Dim emailSubject As String = olItems.Item(i).Subject
                        Dim receiptBody As String = olItems.Item(i).Body
                        'Check for return messages that get deleted without processing.
                        keyIndexSubject = ContainsValue(_deleteAtOnce, emailSubject)

                        If keyIndexSubject Is String.Empty Then
                            delKey = 1
                            keyIndexSubject = ContainsValue(_deleteMessages, emailSubject)
                            keyIndexBody = ContainsValue(_deleteMessages, receiptBody)
                            'If no deleted flags, check for messages that get marked.
                            If keyIndexBody Is String.Empty Then
                                keyIndexBody = ContainsValue(_strikeMessages, receiptBody)
                            Else
                                delKey = -1
                            End If

                            If keyIndexSubject Is String.Empty Then
                                keyIndexSubject = ContainsValue(_strikeMessages, emailSubject)
                            Else
                                delKey = -1
                            End If

                            If TypeOf olItems.Item(i) Is Outlook.ReportItem Then
                                cnt += 1
                                Dim report As Outlook.ReportItem = CType(olItems.Item(i), Outlook.ReportItem)
                                If report.Attachments.Count > 0 Then
                                    Dim returnedEmail As Outlook.Attachment = report.Attachments.Item(1)
                                    returnedEmail.SaveAsFile("c:\" & returnedEmail.FileName)
                                    Dim emailBody = GetMessageBody("c:\" & returnedEmail.FileName, err)

                                    If err = "" Then
                                        Dim key As String = GetKeyName(String.Empty, keyIndexBody)
                                        Dim invalidEmail As String = RegExValue(emailBody, profile.GetInboxEmailRegExPattern)
                                        Dim matchGuid As String = RegExValue(emailBody, profile.GetInboxGuidRegExPattern)
                                        If CheckIfSubscriberOnly(invalidEmail) Then
                                            DeleteSubscriberEmail(invalidEmail)
                                            olItems.Item(i).Delete()
                                        Else
                                            If Not matchGuid Is String.Empty Then
                                                Dim parsedSubject = emailSubject.Replace("Undeliverable:", String.Empty).Trim
                                                SaveReturnedEmails(matchGuid, invalidEmail, parsedSubject, receiptBody, -1)
                                                olItems.Item(i).Delete()
                                                File.Delete("c:\" & returnedEmail.FileName)
                                                'strMessage = "DELETED: :keyIndexSubject:  " & keyIndexSubject & "  :keyIndexBody:  " & keyIndexBody & " :delKey:  " & delKey & " :Email:  " & invalidEmail & " :GUID: " & matchGuid
                                                'EventLog.WriteEntry("NECSInBox", strMessage)
                                            Else
                                                If Not keyIndexSubject Is String.Empty Or Not keyIndexBody Is String.Empty Then
                                                    'strMessage = "MOVED: :keyIndexSubject:  " & keyIndexSubject & "  :keyIndexBody:  " & keyIndexBody & " :delKey:  " & delKey & " :Email:  " & invalidEmail & " :GUID: " & matchGuid
                                                    'EventLog.WriteEntry("NECSInBox", strMessage)
                                                    Dim parsedSubject = emailSubject.Replace("Undeliverable:", String.Empty).Trim
                                                    matchGuid = GetGuidFromSubject(parsedSubject)
                                                    MoveMailMessageForReview(olInbox, olItems, i)
                                                End If
                                            End If
                                        End If
                                    End If
                                Else
                                    Dim key As String = GetKeyName(String.Empty, keyIndexBody)
                                    Dim invalidEmail As String = RegExValue(report.Body, profile.GetInboxEmailRegExPattern).Trim
                                    Dim matchGuid As String = RegExValue(report.Body, profile.GetInboxGuidRegExPattern).Trim
                                    Dim subject As String = RegExValue(report.Body, profile.GetSubjectFromMessageRegExPattern).Trim
                                    If CheckIfSubscriberOnly(invalidEmail) Then
                                        DeleteSubscriberEmail(invalidEmail)
                                        olItems.Item(i).Delete()
                                    Else
                                        If matchGuid = String.Empty And Not subject = String.Empty Then
                                            matchGuid = GetGuidFromSubject(subject)
                                        End If
                                        If Not matchGuid = String.Empty And Not subject = String.Empty Then
                                            SaveReturnedEmails(matchGuid, invalidEmail, subject, report.Body, -1)
                                            olItems.Item(i).Delete()
                                        Else
                                            MoveMailMessageForReview(olInbox, olItems, i)
                                        End If
                                    End If
                                End If
                            ElseIf TypeOf olItems.Item(i) Is Outlook.MailItem Then
                                    If Not keyIndexBody Is String.Empty Or Not keyIndexSubject Is String.Empty Then
                                        Dim mail As Outlook.MailItem = olItems.Item(i)
                                        Dim invalidEmail As String = RegExValue(mail.Body, profile.GetInboxEmailRegExPattern)
                                        Dim matchGuid As String = RegExValue(mail.Body, profile.GetInboxGuidRegExPattern)
                                    If CheckIfSubscriberOnly(invalidEmail) Then
                                        DeleteSubscriberEmail(invalidEmail)
                                        olItems.Item(i).Delete()
                                    Else

                                        If matchGuid Is String.Empty Or invalidEmail Is String.Empty Then
                                            Dim attachCount As Integer = mail.Attachments.Count
                                            Dim x As Integer = 1
                                            If attachCount > 0 Then
                                                Do While (x < attachCount + 1) Or (keyIndexSubject Is String.Empty And keyIndexBody Is String.Empty)
                                                    Dim mailAttach As Outlook.Attachment = mail.Attachments.Item(x)
                                                    If matchGuid Is String.Empty And mailAttach.FileName.EndsWith("msg") Then
                                                        matchGuid = GetGuidFromSubject(mailAttach.FileName)
                                                    Else
                                                        mailAttach.SaveAsFile("c:\" & mailAttach.FileName)
                                                        Dim attachBody = GetMessageBody(GetFileAttachmentName(x), err)
                                                        If invalidEmail Is String.Empty Then
                                                            invalidEmail = RegExValue(attachBody, profile.GetInboxEmailRegExPattern)
                                                        End If
                                                        If matchGuid Is String.Empty Then
                                                            matchGuid = RegExValue(attachBody, profile.GetInboxGuidRegExPattern)
                                                        End If
                                                        File.Delete("c:\" & mailAttach.FileName)
                                                        x += 1
                                                    End If
                                                Loop
                                            Else
                                                'No Attachments....  No guid.... look for subject in text of email.
                                                Dim newSubject As String = RegExValue(mail.Body, profile.GetSubjectFromMessageRegExPattern)
                                                If Not newSubject Is String.Empty Then
                                                    matchGuid = GetGuidFromSubject(newSubject)
                                                End If
                                            End If
                                        End If
                                    End If
                                    If Not matchGuid Is String.Empty And Not invalidEmail Is String.Empty Then
                                        Dim parsedSubject = emailSubject.Replace("Undeliverable:", String.Empty).Trim
                                        SaveReturnedEmails(matchGuid, invalidEmail, parsedSubject, receiptBody, -1)
                                        olItems.Item(i).Delete()
                                        'strMessage = "DELETED: :keyIndexSubject:  " & keyIndexSubject & "  :keyIndexBody:  " & keyIndexBody & " :delKey:  " & delKey & " :Email:  " & invalidEmail & " :GUID: " & matchGuid
                                        'EventLog.WriteEntry("NECSInBox", strMessage)
                                    Else
                                        If Not keyIndexSubject Is String.Empty Or Not keyIndexBody Is String.Empty Then
                                            'strMessage = "MOVED: :keyIndexSubject:  " & keyIndexSubject & "  :keyIndexBody:  " & keyIndexBody & " :delKey:  " & delKey & " :Email:  " & invalidEmail & " :GUID: " & matchGuid
                                            'EventLog.WriteEntry("NECSInBox", strMessage)
                                            MoveMailMessageForReview(olInbox, olItems, i)
                                        End If
                                    End If
                                End If
                                Else
                                    MoveMailMessageForReview(olInbox, olItems, i)
                                End If
                            Else
                            'delete message with no processing
                            olItems.Item(i).Delete()
                        End If
                    Next i

                Catch ex As Exception
                    WriteToEventLog(ex.ToString)
                Finally
                    olNS.Logoff()
                    olApp = Nothing : olNS = Nothing
                    olItems = Nothing : olInbox = Nothing
                    If profile.WriteServiceTotalUndeliveredEmailsToLog Then
                        WriteToEventLog(profile.GetTotalUndeliveredEmailsMessage.Replace("?", cnt))
                    End If
                End Try
            Else
                If profile.WriteServicePauseMessageToLog Then
                    WriteToEventLog(profile.GetServicePauseMessage)
                End If
            End If
        Catch outEx As Exception
            WriteToEventLog(outEx.ToString)
        End Try
    End Sub

regards,
Brian
The problem with doing something right the first time is that nobody appreciates how difficult it was.
 
Yeah, pretty close I think, except it doesn't iterate through exchange directly, but rather, iterates through MS Outlook's Inbox, which is a mail client to an Exchange server. I don't supply any parameters to my windows service and I don't think the current compiled version will help you much. I would recommend just retro-fitting the above code into your existing model. What you see above is the bulk of the logic that does all the work. Let me know if you need any of the helper/supporting functions which exist. They're pretty basic and relatively specific to our application, so it may not matter to you. Hope this helps.

regards,
Brian
The problem with doing something right the first time is that nobody appreciates how difficult it was.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top