[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

Outlook item.save method

I am writing an app that creates messages and sends them to Microsoft Outlook using the following code:

Public Sub SaveOutlookMail(Subject As String, Recipient As _
String, Message As String)

Dim oLapp As Object
Dim oItem As Object

Set olApp = CreateObject("Outlook.application")
Set olItem = olApp .CreateItem(olMailItem)

With olItem
   .Subject = Subject
   .Recipients.Add (Recipient)
   .body = Message
   .Save
End With

Set olApp = Nothing
Set olItem = Nothing

Exit Sub

I would like the messages to be saved in the outbox to be sent later, but, for some reason, my messages are being saved to the inbox. Can anyone explain this please.
0
STKeith
Asked:
STKeith
  • 5
  • 5
1 Solution
 
Bob LearnedCommented:
Unfortunately, the Save method saves the MailItem to the default folder.  

There is, however, a Move method that would let you move it to the Outbox from the Inbox.
0
 
STKeithAuthor Commented:
Thanks for the info. I have tried the Move method, but I can't get the message to Save and then Move within the same instance of the app. It only works if I save first, close the app, open a new instance of the app, find the message, and then move it.
0
 
Bob LearnedCommented:
I tried this to test the theory out:

Dim appOutlook As New Outlook.Application
Dim itmMail As Outlook.MailItem
Dim foldDestination As Outlook.MAPIFolder


   Set itmMail = appOutlook.CreateItem(olMailItem)
   
   Set foldSource = appOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderDrafts)
   Set foldDestination = appOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderOutbox)
   
   With itmMail
      .To = "Robert Learned"
      .Subject = "Test"
      .Body = "This is a test"
      .Save
      .Move foldDestination
   End With


The new mail item was saved into the Draft folder, and moved into the Outbox.
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
STKeithAuthor Commented:
This code does not work for me, I get the following error when it reaches the Move method:

Run-time error '-2147417851':
Method 'Move' of object '_DMailItem' failed.
0
 
Bob LearnedCommented:
A good place to start would be to ask what version of Outlook are you using?  I am using Outlook 98?

The next question would be what platform?  I am using Windows NT 4.0 SP5.
0
 
STKeithAuthor Commented:
I am using Outlook 97 and Windows 95.
0
 
Bob LearnedCommented:
Have you ever thought about upgrading to Outlook 98?  It's a free upgrade from Micro$oft!
0
 
STKeithAuthor Commented:
I'll look into it. Thanks.
0
 
Bob LearnedCommented:
Was this any help to you?
0
 
STKeithAuthor Commented:
Yes, this was helpful. I still have to do a couple of "work-arounds" between saving and moving, but I think I can get the job done now. Thanks.
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

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