x1877
asked on
How can i send automatic emails on contacts birthday in Outlook?
How can i send automatic emails on contacts birthday in Outlook? If not possible by default settings can i write some VBA code? Appreciate any help...
ASKER
Yes, Outlook needs to be running, thats totally understandable. Please go ahead this route&
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
BlueDevilFan: Thanks. I think this what i exactly wanted, let me try this, i will get back if i need more assistance.
You're welcome. I'll be here if you need anything.
As I said... :-)))
ASKER
Thanks Bembi for your tips
ASKER
BlueDevilFan: This code is excellent, but i need to access the contacts synced from Live Calendar also, I think i need to make some changes in this line
Set olkContacts = Session.GetDefaultFolder(o lFolderCon tacts).Ite ms
Am i right?
Set olkContacts = Session.GetDefaultFolder(o
Am i right?
If the contacts you want to process are not in the default contacts folder, then "yes" you will need to change that line. I'd need to know the path to the folder in question to be able to advise you on how to change the line though.
ASKER
Yes i could successfull access the hotmail contacts by passing entryid of the folder. Just one more doubt...Can i do this whole process in a seperate windows exe, without ever running outlook?
Yes, if you are an expert at programming in MAPI you could bypass Outlook. Otherwise, no.
ASKER
All rt, Hope 1 day i can be an expert in MAPI. Thanks for all your help and Bembis tips. Here i am posting my modfied code. might help some one some day... I may ask for more help incase i need to move this code a seperate exe.
Dim nameSpace As nameSpace
Function GetEntryID(MailFolder) As String
Dim folders As Object
Dim folder As Object
Set folders = nameSpace.folders
For Each folder In folders
If MailFolder = folder.Name Then
Dim i As Integer
For i = 1 To folder.folders.Count
If UCase(folder.folders(i).Name) = UCase("contacts") Then
GetEntryID = folder.folders(i).entryID
Exit For
End If
Next
Set folders = Nothing
Set folder = Nothing
Exit Function
End If
Next
End Function
Private Sub Application_Startup()
Dim entryID As String
Set nameSpace = Application.GetNamespace("MAPI")
entryID = GetEntryID("******@hotmail.com")
SendBirthdayMessage (entryID)
End Sub
Private Sub Application_Quit()
Set objNS = Nothing
End Sub
Sub SendBirthdayMessage(HotEntryID As String)
Dim contacts As Object
Dim contact As Object
Dim message As Outlook.MailItem
Set contacts = Session.GetFolderFromID(HotEntryID).Items
For Each contact In contacts
If contact.Class = olContact Then
If (Month(contact.Birthday) = Month(Date)) And (Day(contact.Birthday) = Day(Date)) Then
Set message = Application.CreateItem(olMailItem)
With message
.Recipients.Add contact.Email1Address
.BCC = "******@hotmail.com"
'Change the subject as needed'
.Subject = "Happy Birthday " & contact.Subject
'Change the message as needed'
.HTMLBody = "Wish you a very happy birthday. "
'Change Display to Send if you want the messages sent automatically'
.Display
End With
End If
End If
Next
Set message = Nothing
Set contact = Nothing
Set contacts = Nothing
End Sub
I'm not a MAPI expert, so if you want to go that route I'm afraid I won't be able to help. MAPI programming is usually, perhaps always, done in C.
ASKER
It should not be very hard to in C# also i think.
Just found some code, though i did not tried ...
msoutl9.Application objOutlook = new msoutl9.ApplicationClass() ;
msoutl9.NameSpace objNS = objOutlook.GetNamespace("M API");
objNS.Logon ("exchtest","net",false,tr ue);
msoutl9.Application objOutlook = new msoutl9.ApplicationClass() ;
msoutl9.NameSpace objNS = objOutlook.GetNamespace("M API");
objNS.Logon ("exchtest","net",false,tr ue);
Just found some code, though i did not tried ...
msoutl9.Application objOutlook = new msoutl9.ApplicationClass()
msoutl9.NameSpace objNS = objOutlook.GetNamespace("M
objNS.Logon ("exchtest","net",false,tr
msoutl9.Application objOutlook = new msoutl9.ApplicationClass()
msoutl9.NameSpace objNS = objOutlook.GetNamespace("M
objNS.Logon ("exchtest","net",false,tr
when i execute the macro: Sub SendBirthdayMessage()
i get the error: "een door de gebruiker gedefinieerd gegeventype is niet gedefinieerd" op line:
Dim olkContacts As Outlook.Items, _
olkContact As Object, _
olkMsg As Outlook.MailItem
how can i solve that?
i get the error: "een door de gebruiker gedefinieerd gegeventype is niet gedefinieerd" op line:
Dim olkContacts As Outlook.Items, _
olkContact As Object, _
olkMsg As Outlook.MailItem
how can i solve that?
Outlook does not have a built-in means of doing this. I can do it with a bit of scripting, but Outlook will have to be open for the script to work. In other words, if a birthday occurs on a day when Outlook is not running, then a birthday email would not be sent. I can provide the code and instructions if you want to go this route.