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

Placing email in 'Sent Items' folder 1

Status
Not open for further replies.

Laaitie

Programmer
Dec 1, 2003
20
0
0
ZA
I've been searching the net as well as the MSDN Library but only found questions without answers.

What I want to do is to place an email in the end-users 'Sent Items' folder.

The user will not compile this email, and it will not be send from his PC either. No SMTP server on the client side will see this email. May sound weird, but basicly he'll enter a couple of fields, this data will be send via satellite and on the receiving side the email will be compiled and send off.

I've found code I can use to write dll drivers to do this but the API calls differs for each version of Outlook, so a different dll for each Outlook version and this will not work with Outlook Express. And, off course, if possible I don't want my solution be limted to the Outlook family. Therefor using VBA macros is also not an perfect solution.

Code would be welcome;) but if someone can just direct me in the right direction: tell me what objects, functions, websites to look at.

Please just note that I still code in VB6.

Thanks
 
I dont think you can add things easily to a 'sent' email in the sent folder.
The idea of a sent folder is that you shouldnt be able to alter it as it is a true record of what was sent.
Otherwise you could easily frame somebody for sending something they really didn't send!
Perhaps you could just store it in a temporary database file then send it properly once it has been finished?
 
I don't believe this will be possible. There are so many different e-mail clients each with its own proprietory information stores and normally no programmable interface (this includes Outlook Express).

If you target Outlook then it's simple. You can late bind to Outlook objects so the same code will run with any version of Outlook.
Code:
Dim objApp As Object
Dim objNS As Object
Dim objFolder As Object
Dim objMsg As Object
Dim objRecip As Object

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(5) 'olFolderSentMail
Set objMsg = objFolder.Items.Add
With objMsg
 Set objRecip = .Recipients.Add("joe@nowhere.com")
 objRecip.Type = 1 'olTo
 .Subject = "Subject"
 .Body = "My message"
 .Save
End With

Set objRecip = Nothing
Set objMsg = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing

Paul Bent
Northwind IT Systems
 
Sorry to gatecrash, but what folder number equates to the Outbox (ready to send), and is it possible for it to include an attachment. Worth a star if you can do it. Applogogies to Laaitie for intrusion, but very near what I was looking for. Thanks
 
This should cover it:
Code:
Dim objApp As Object
Dim objNS As Object
Dim objFolder As Object
Dim objMsg As Object
Dim objRecip As Object

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(4) 'olFolderOutbox
Set objMsg = objFolder.Items.Add
With objMsg
 Set objRecip = .Recipients.Add("joe@nowhere.com")
 objRecip.Type = 1 'olTo
 .Subject = "Subject"
 .Body = "My message"
 .Attachments.Add _
 "x:\mypath\myfile.zip", , "Display Name"
 .Save
End With

Set objRecip = Nothing
Set objMsg = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing

Paul Bent
Northwind IT Systems
 
Your the man Paul, thanks very much. Got your star.
 
Hi Paul, just tried it and it puts it in the InBox, not the outbox for sending. Any ideas, thanks
 
Paul's first example..

Set objFolder = objNS.GetDefaultFolder(5) 'olFolderSentMail

Paul's second example..

Set objFolder = objNS.GetDefaultFolder(4) 'olFolderOutbox

If 4 is the inbox then try 3 or 2, I wouldnt have a clue but seems logical to me.

 
ZOR,

Which version of Outlook? Outbox is definitely 4, Inbox is 6. I wonder if the Save is doing it. What happens if you omit the Save?

I can check it out tomorrow, it's 11:00 pm here in the UK and I'm just about to log off, pour a large malt and chill :)

Paul Bent
Northwind IT Systems
 
Thanks LPlates, I know I did poke about with Pauls first version but could not do it. I'll try it again later and see where it goes. Regards
 
Doesnt matter what I select, they all end up in the drafts folder, lol. Also, a msgbox pops up warning of virus like activity and I have options to allow access to outlook for up to 10min's. Kinda defeats the whole purpose of 'placing' bogus mails in someones sent folder or outbox.

ZOR, Are you getting the same msgbox popup?
 
LPlates,

The "popup" is from the Outlook Object Model Guard which was introduced in Office 2000 SR-2 or if the Outlook Security patch is applied to 97, 98 or 2000. Best way round it is to use Dimitri Streblechenko's Redemption control
ZOR,

As far as I remember, the Drafts folder was introduced in OL2000 but I don't have a 98 system any more to check this. Perhaps you're using 98 or earlier and mail items are saved to the Inbox. The item must be saved or it won't appear in any folder. Use the Move method after saving to transfer it to the Outbox. This worked fine with OL2000:
Code:
Dim objApp As Object
Dim objNS As Object
Dim objFolder As Object
Dim objMsg As Object
Dim objRecip As Object

Set objApp = CreateObject("Outlook.Application")
Set objNS = objApp.GetNamespace("MAPI")
Set objFolder = objNS.GetDefaultFolder(4) 'olFolderOutbox
Set objMsg = objApp.CreateItem(0) 'olMailItem
With objMsg
 Set objRecip = .Recipients.Add("joe@nowhere.com")
 objRecip.Type = 1 'olTo
 .Subject = "Subject"
 .Body = "My message" & vbCrLf & vbCrLf
 .Attachments.Add _
 "n:\scratch\control.zip", 1, , "Control Files"
 .Save
 .Move objFolder
End With

Set objRecip = Nothing
Set objMsg = Nothing
Set objFolder = Nothing
Set objNS = Nothing
Set objApp = Nothing

Paul Bent
Northwind IT Systems
 
If you connect to Outlook, then create a new email and send it using the various objects, then a copy will be saved in the Outbox in the normal way.

So use the CreateItem method of the Outlook.Application object, specify the type as olMailItem. This will return a MailItem object, you can then set the properties (ie To and Body) and use the Send method. So similar much the code given above, but using .Send instead of .Save. The item will then be put in the Outbox and Sent Items folders.

Hope this helps


Jonathan
tektips@jonathangeorge.co.uk
 
Jonathan,

ZOR asked for the e-mail to be created in the Outbox ready for sending, not to be sent.

Also, a sent mail item is saved in the Sent Items folder, not the Outbox.

Paul Bent
Northwind IT Systems
 
True - a misstyping on my part. Laaitie (who started the thread) wanted stuff in the Sent Items folder.

The method I described would place the message in the Outbox from where it would be sent. It would also place a copy in Sent Items, in the same way as happens when an email is sent manually in Outlook.



Jonathan
tektips@jonathangeorge.co.uk
 
Although re-reading the original post, the method I described wouldn't work for Laaitie anyway. Oops.


Jonathan
tektips@jonathangeorge.co.uk
 
Blimey, what a lot of activity after I shut down. Thanks Paul, that works perfectly. Version I have is Outlook 97, does not have SR2, no nasty virus warning messages, just works well. Thanks all. Don't know where Laaitie went?, but thanks for starting the thread. Sorry Paul, can't add another star.
 
Wow. I've placed this question on 9 VB forums, but this is the only one that started some discussion. Thanks for all the contributions. Specially Paul.

Guess I'll just have to stick to an Outlook only solution:(

Fine for gatecrashing ZOR. At least now we’ve got all this mail issues under one thread.

PS. One of my colleagues has ridiculed me for my bad grammar;) Sorry guys, I'll try to rectify that next time:)
 
I'm sort of familiar with using Novell GroupWise with this type of thing. If you would like to see that, let me know.
 
Thanks Laaitie, glad we/all got something from it. This site is by far the best, having so many actively helpful people on it with lots of knowledge that they are only too pleased to pass on in help. Always good to Mark the post with a star to show appreciation on helpful threads. Best regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top