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

Email not copying to Sent Items in Outlook

Status
Not open for further replies.

AndyLord

Programmer
Jun 30, 2004
45
GB
To all

I have a asp page that will allow the user to send an emial using CDONTS, with an attachment to client, which works fine. The attachement can be either in DOC of PDF format. Again this works fine. The problem I have and I assume it something not configured, that the user who sends the email does not have a copy in their Outlook Sent Items folder.
How do I get a copy of the sent email to the Sent Items folder?

The following is the code that sends the email:

<%

Dim objNewMail
Dim MapDOC
Dim MapPDF

Set objNewMail = Server.CreateObject("CDONTS.NewMail")

objNewMail.MailFormat = 0
objNewMail.To = Request.Form("txtClientEmail")
objNewMail.From = Request.Form("txtSenderEmail")
objNewMail.Subject = Request.Form("txtSubject")
objNewMail.Body = Request.Form("txtComments")

MapDOC = Request.Form("MapDOCVersion")
MapPDF = Request.Form("MapPDFVersion")

If MapDOC <> "Select Word Format Map" Then
objNewMail.AttachFile "C:\path\"&MapDOC, MapDOC, 1
objNewMail.Send ,,,, 2
Response.Write vbCrLf & "<Font Face=""Arial"">Message sent to - <b>" & Request.Form("txtClientEmail") & "</b></Font>"
Response.Write vbCrLf & "<br>"
Response.Write vbCrLf &"<font face=""Arial"">File sent as - <b>" & MapDOC & " </b>format</font>"
Elseif MapPDF <> "Select PDF Format Map" Then
objNewMail.AttachFile "C:\Path\"&MapPDF, MapPDF, 1
objNewMail.Send ,,,, 2
Response.Write vbCrLf & "<Font Face=""Arial"">Message sent to - <b>" & Request.Form("txtClientEmail") & "</b></Font>"
Response.Write vbCrLf & "<br>"
Response.Write vbCrLf &"<font face=""Arial"">File sent as - <b>" & MapPDF & " </b>format</font>"
Else
Response.Write vbCrLf & "<Font Face=""Arial"">Message NOT sent to - <b>" & Request.Form("txtClientEmail") & "</b></Font>"
Response.Write vbCrLf & "<br>"
Response.Write vbCrLf &"<font face=""Arial"">Select a to file send</font>"
End If
%>

Again the code works I need help getting a copy of the sent email into the Sent Items Outlook folder.

Many thanks in advance
 
>>How do I get a copy of the sent email to the Sent Items folder?



all mails sent by IIS are stored in a seperate folder (in ur inetpub u will be having a Mail folder). u cannot get this into outlook express as both maintain their mails seperately...

Known is handfull, Unknown is worldfull
 
Change the line :
Code:
objNewMail.To = Request.Form("txtClientEmail")
to
Code:
objNewMail.To = Request.Form("txtClientEmail") & ";youraccount@yourcompany.com"
make youraccount@yourcompany.com your email adres. On this way you get an copy of the mail. :)
 
Right, you can send a copy to the user, but that's the only way they'll get it. CDONTS is on the server itself, it's not using the client's machine to send the mail (the user could have no email program installed at all). There's no mail being sent from their machine, hence nothing in the Sent Mail folder.
 
Many thanks to all who have replied but I think some people may be misunderstanding me. The Client receives the email ok, the problem is that the person who sends the email, from the intranet web page, does not get a copy of the email in their outlook sent items folder. This will be required as there may be a requirement to resend the email again.

Thats what I wish to achieve and not fully sure if this can be done. Further investigation has pointed me to Microsoft website and discovered that you can use CDONTS.Session where you can add the out-going message to the Outbox. Iam i right in thinking if the message goes throught the outbox then a copy should be saved in the sent items? Or am I isunderstanding this.
 
You can also store the email in a small database before sending via CDONTS.

My thoughts:
[ul][li]Store all the user input (and save the attachment to your server) from the original web form to a database as well as sending the email.[/li]
[li]Also assign a unique ID to each email stored in your database.[/li]
[li]Send a "receipt" email to the user that references that same page with the unique email ID in the querystring parameters[/li]
[li]Use that unique ID to retrieve the previously sent email.[/li][/ul]

This way you can have the user come back to the web form and modify the email, too, before re-sending. If you are worried about security since the "unique ID" is quite transparent, you can also ask the user to assign a passowrd to retrieve the email... or whaterver security measure suites your fancy.

Earnie Eng
 
The Microsoft article is referring to the outbox on the server, not the client. Let me try to explain.

1. Client (browser) requests your web page.

2. Client (browser) fills out a form or whatever and sends the data to the server, just like any other form or query.

3. Server taket the request and sends an email via CDONTS. Notice that the Client -- the place where the browser and the Outlook in question -- isn't doing anything at this stage. In fact, the only thing it's doing is waiting for the server to send it another web page in response to the form data.

4. Server sends and "OK" page (or whatever) to the Client.

At no point did the client ever send an email, so there's nothing in their Sent Items folders. They didn't send anything! The server sent an email (via CDONTS). The client just browsed web pages.

Ahmun's suggestion sounds like a good solution to your needs, imo.

One more bit of clarification, just in case: CDONTS isn't a method for making the Client -- the guy with the browser -- send an email. It's a method for making the server -- the machine that IIS and ASP are running on -- send an email.

Make sense?
 
Many thanks to all, an apologies if I got confused. Anyway I have managed to resolve this issue by using CreateObject("Outlook.Application"). This does exactly what I wanted to achieve.

Many thanks again to all.
 
ADDITIONAL: HELP PLEASE IF YOU CAN
The above method works fine, if Intranet is on client PC. Will not work however if Intranet on server, then get

Microsoft VBScript runtime (0x800A01AD)
ActiveX component can't create object: 'Outlook.Application'

Does anyone know, and I realise the security issues of this, a way that teh Intranet on the server can open up a clients Outlook and send an email. I have included the code below, which works if the Intranet is on the clients PC.

'##########################################################
Dim objOutlk 'Outlook
Dim objMail 'Email item
Dim strMsg
Const olMailItem = 0

'Create a new message
Set objOutlk = createobject("Outlook.Application")
Set objMail = objOutlk.createitem(olMailItem)
objMail.To = Request.Form("txtClientEmail")
'objMail.cc = "" 'Enter an address here To include a carbon copy; bcc is For blind carbon copy's

'Set up Subject Line
objMail.subject = Request.Form("txtSubject")' & cstr(month(now)) & "/" & cstr(day(now)) & "/" & cstr(year(now))
'Add the body

strMsg = Request.Form("txtComments")
'strMsg = strMsg & "I voted and gave you an excellent rating!"
'To add an attachment, use:

MapDOC = Request.Form("MapDOCVersion")
MapPDF = Request.Form("MapPDFVersion")
CheckEmail = Request.Form("txtClientEmail")

If CheckEMail <> "" Then
If MapDOC <> "Select Word Format Map" Then
objMail.attachments.add("C:\PATH OF DOCUMENT\") & MapDOC
objMail.body = strMsg
objMail.display 'Use this To display before sending, otherwise call objMail.Send to send without reviewing
Elseif MapPDF <> "Select PDF Format Map" Then
objMail.attachments.add("C:\PATH OF DOCUMENT\") & MapPDF
objMail.body = strMsg
objMail.display 'Use this To display before sending, otherwise call objMail.Send to send without reviewing
Else
Response.Write vbCrLf & "<Font Face=""Arial""><b>Message NOT sent. </b></Font>"
Response.Write vbCrLf & "<br>"
Response.Write vbCrLf &"<font face=""Arial"">Select a to file send</font>"
End If
Else
Response.Write vbCrLf & "<Font Face=""Arial""><b>You have not entered an email address. </b></Font>"
Response.Write vbCrLf & "<br>"
Response.Write vbCrLf &"<font face=""Arial"">Please enter email address and try again.</font>"
End If

Response.Redirect ("email.asp")
'Clean up
Set objMail = nothing
Set objOutlk = nothing
'##########################################################

Many thanks in advance
 
that's because it needs Outlook to be installed on the machine the script runs on and would add it to the sent items for that user/machine.

What you are trying to do (as others have said) is simply not possible. You are trying to mix a server-side operation (CDONTS/CDOSYS sending email) with a client side event (Outlook/Outlook Express sending email). It's like sending an email using Hotmail, Yahoo etc and expecting that to turn up in Outlook's sent items. IT DOESN'T HAPPEN.

There is a method of using javascript to send through the default mail client on the users machine, but this does raise security alerts and will be blocked by some security settings.



Chris.

Indifference will be the downfall of mankind, but who cares?
A website that proves the cobblers kids adage.
Nightclub counting systems

So long, and thanks for all the fish.
 
Thanks ChrisHirst, I think that I will have to use CDONTS/CDOSYS to send email and not worry about retaining a copy of the mail sent out.

Again many thanks to all for advice etc.
 
Another idea is: Try creating an email link that will open up the user's outlook for him/her to send. If you click the following link, and your computer (or your client's) has Outlook set has designated email handler, it will open up a new email: test@someServer.com

Here are the steps to achieve that:
[ol][li]Create your web page with the form to fill out[/li]
[li]On the submit button, set it to do nothing and add some javascript.[/li]
[li]You can put this javascript on the onClick event of the button.[/li]
[li]The Javascript should read the values typed in the form fields and insert it into an email mailto link. After assembling this link, re-direct the user to that mailto link to force Outlook to open an email.[/li]
[li]Additionally, you can also have the form post after generating the email link so you can still store the email in a database.[/li][/ol]

The javascript would look something like this (not checked for syntax):
Code:
function SendMailtoLink(strEmail) {
  var strBody, strSubject;
  strSubject = document.formname.subject.value;
  strBody = document.formname.body.value;
  document.location = "mailto:" + strEmail
                    + "?subject=" + strSubject
                    + "&strBody=" + strBody;
}

Some considerations:
[ul][li]There is a string length limitation to the mailto link[/li]
[li]You may be limited in the number of options.[/li][/ul]


Some resources:
[ul][li]MSDN's documentation on the mailto protocol: [/li]
[li]Browse through the javascript forum on this site for ideas.[/li]
[li]Check out DevGuru for great reference on syntax and usage: [/li][/ul]

Good luck!

Earnie Eng
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top