Using VB to open mail.oft and complete the email

J Trahair

Well-known member
Joined
May 14, 2008
Messages
175
Location
Spain
Programming Experience
10+
I need to automate sending an email normally created manually by opening mail.oft (which gives an email format with the customer's business header and a footer). This is because the UK is still facing postal (mail) strikes.

Opening mail.oft from within VB is easy, but once open how can I 'grab' the window and populate the To:, Subject: and Text?

Or is there a way of applying the header and footer images from within the following code which successfully send a plain email: (customer uses Vista)

VB.NET:
        ' Start Outlook.
        ' If it is already running, you'll use the same instance...
        Dim olApp As Outlook.Application
        olApp = CreateObject("Outlook.Application")

        ' Logon. Doesn't hurt if you are already running and logged on...
        Dim olNs As Outlook.NameSpace
        olNs = olApp.GetNamespace("MAPI")
        olNs.Logon()

        ' Send a message to your new contact.
        Dim olMail As Outlook.MailItem

        olMail = olApp.CreateItem(Outlook.OlItems.olMailItem)
        ' Fill out & send message...
        olMail.To = "me@my.co.uk"
        olMail.Subject = "About our meeting..."
        olMail.Body = "Dear Fred, " & vbCr & vbCr & vbTab & _
             "I'll see you in 2 minutes for our meeting!"
        olMail.Send()

        ' Clean up...
        MsgBox("All done...", vbMsgBoxSetForeground)
        olNs.Logoff()
        olNs = Nothing
        olMail = Nothing
        olApp = Nothing

Thanks again.
 
Back
Top