How to create the sent mail in SendItems folder???

G

Guest

I´m using Access 2000 to generate a file from the database and then I
send it as an attachement to the mail using the following code witch works
perfectly:
Dim iMsg As Object
Dim iConf As Object
Dim iBP
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")

With iMsg
Set .Configuration = iConf
.To = "(e-mail address removed)"
.From = """Darivan"" <[email protected]>"
.Subject = "Darivan Reklam (Fakturafil) "
.HTMLBody ="<html> some text here</html>"
Set iBP = iMsg.AddAttachment("C:\Reklam_" & Me!Date.Value &
".txt")
.Send
End With

Set iBP = Nothing
Set iMsg = Nothing
Set iConf = Nothing

Can I get a simple code to create the sent mail in SentItems folder with the
attachement file as if it was sent from Outlook?

So please help me get started
thank you
 
D

David C. Holley

I do know that when you use Outlook Object Model to send the email as in

Dim appOutlook as Outlook.Application
Dim newMail As MailItem

Set objOutlook = CreateObject("Outlook.application")
Set newAppt = objOutlook.CreateItem(olAppointmentItem)

with newAppt
.Send
end with

objOutlook.Quit
set newAppt = Nothing
set objOutlook = Nothing


Outlook will save a copy in the Sent Items folder, provided that the
Option is selected in the Options Dialog.

TOOLS > OPTIONS > PREFERENCES > EMAIL OPTIONS

Save Copies of messages in Sent Items Folder.

I'm not the expert on where CDO fits into things, however I would first
check that setting and try the code then. If it still doesn't capture
it, I would convert to using Outlook as shown above. The properties of
MailItem are essentially the same as a Message in CDO, plus probably a
few more.
 
K

Ken Slovak - [MVP - Outlook]

Not if you use Simple MAPI as you are. You'd need to use CDO 1.21 instead,
however that would fire the security prompts. Simple MAPI has no connection
to Outlook and you can't control where the item is stored using that API.
 
G

Guest

Hi Ken,

What would be the solution?
I heard about Redemption but there was no dokumentation as a download.
If possible the code needed to acomplish the task (send a mail and save it
in SendItems).
best reguards
Mustapha

"Ken Slovak - [MVP - Outlook]" skrev:
 
D

David C. Holley

See my prior post for 1 option.
Hi Ken,

What would be the solution?
I heard about Redemption but there was no dokumentation as a download.
If possible the code needed to acomplish the task (send a mail and save it
in SendItems).
best reguards
Mustapha

"Ken Slovak - [MVP - Outlook]" skrev:

Not if you use Simple MAPI as you are. You'd need to use CDO 1.21 instead,
however that would fire the security prompts. Simple MAPI has no connection
to Outlook and you can't control where the item is stored using that API.
 
K

Ken Slovak - [MVP - Outlook]

There are many samples at the Redemption Web site that cover situations such
as yours.

If the user has set to have sent items moved to the Sent Items folder that
part's automatic. Here's what Redemption code would look like for doing what
you want:

Dim oMail As Outlook.MailItem
Dim safMail As Redemption.SafeMailItem
Dim oNS As Outlook.NameSpace
Dim oOL As Outlook.Application

Set oOL = CreateObject("Outlook.Application")
Set oNS = oOL.Session
oNS.Logon

Set oMail = oOL.CreateItem(olMailItem)
With oMail
.Subject = "Darivan Reklam (Fakturafil) "
.HTMLBody ="<html> some text here</html>"
.Attachments.Add "C:\Reklam_" & Me!Date.Value & ".txt"
.Save
End With

Set SafMail = CreateObject("Redemption.SafeMailItem")
safMail.Item = oMail
With safMail
.Recipients.Add "(e-mail address removed)"
.Recipients.ResolveAll
.Send
End With

' release all objects here
 
D

David C. Holley

For that matter if you're using the Outlook.Application object why not
just use

Set newMailItem = oOL.CreateItem(olMailItem)

and then
newMailItem.send

David H
 
K

Ken Slovak - [MVP - Outlook]

The Send method is restricted and will bring up the security prompts even in
Outlook 2003 if the code is not running in a trusted Outlook COM addin.
That's why Redemption is used. Outlook 2002 and earlier don't have trusted
COM addins at all, other than when set using the Exchange security form.
Therefore they need to use Redemption or some equivalent.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top