Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes


Visual Basic Programming Code Examples

Visual Basic > Internet Web Mail Stuff Code Examples

Forward new outlook mail and appointments

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
Forward new outlook mail and appointments The following code demonstrates a simple method of forwarding new email and appointments to a specified email address. Paste the following code into a class module and if you are working outside the Outlook VBA environment you will need to add a reference to "Microsoft Outlook 9.0 Object Library". NOTE: Add to following code to a Class module and name the Class clsFoward Option Explicit Private WithEvents oOutlook As Outlook.Application Private WithEvents oMailItems As Outlook.Items Private WithEvents oCalendarItems As Outlook.Items Private zsForwardTo As String Private Sub Class_Initialize() 'Create an private outlook session Set oOutlook = New Outlook.Application 'Get the calendar and inbox objects Set oMailItems = Outlook.Session.GetDefaultFolder(olFolderInbox).Items Set oCalendarItems = Outlook.Session.GetDefaultFolder(olFolderCalendar).Items End Sub Private Sub Class_Terminate() Set oOutlook = Nothing Set oMailItems = Nothing Set oCalendarItems = Nothing End Sub 'Forward New Appointments Private Sub oCalendarItems_ItemAdd(ByVal Item As Object) Dim oForward As MailItem If TypeName(Item) = "AppointmentItem" Then 'Forward the appointment Set oForward = Item.ForwardAsVcal oForward.Recipients.Add zsForwardTo 'Send it oForward.Send Set oForward = Nothing End If End Sub 'Forward New Mail Private Sub oMailItems_ItemAdd(ByVal Item As Object) Dim oForward As MailItem If TypeName(Item) = "MailItem" Then 'Forward the item just received Set oForward = Item.Forward 'Address the message oForward.Recipients.Add zsForwardTo 'Send it oForward.Send Set oForward = Nothing End If End Sub Property Get ForwardTo() As String ForwardTo = zsForwardTo End Property Property Let ForwardTo(Value As String) zsForwardTo = Value End Property NOTE: Add this code to a Standard Module and call the StartForward routine to begin the fowarding. Option Explicit Private oMailForward As clsFoward Sub StartForward() Set oMailForward = New clsFoward oMailForward.ForwardTo = "[email protected]" End Sub Sub StopForward() Set oMailForward = Nothing End Sub