Suntower
Posts: 225
|
| Posted: 09/06/2006, 8:42 AM |
|
I have a typical form for sending an e-mail. There is an INPUT<> for adding an attachment. But it appears there is something I am not understanding about VB syntax
In the onclick event for the 'submit' button...
DIM MyAttachment
DIM MailerObj
MyAttachment = NewRecord.TextBox1.Value 'This is the attachment field
'Send message to Distributor
Set MailerObj =Server.CreateObject("CDO.Message")
MailerObj.From = Session("GLO_Server_EmailFromAddress")
MailerObj.To = Session("GLO_Server_General_EmailToAddress")
MailerObj.Subject= NewRecord.MessageSubject.Value
MailerObj.TextBody=NewRecord.MessageBody.Value
IF rtrim(MyAttachment) <> "" THEN
MailerObj.AddAttachment MyAttachment
END IF
MailerObj.Send
OK. If I use a regular text input field, this will work (so long as the filename in the field is absolutely correct, of course.) HOWEVER, if I change the INPUT<> to type 'file', this doesn't work. What happens is that there is either an ASP error -or- the e-mail gets sent but the attachment is completely wrong---it's an empty file named like the subject line.
How come? What -is- the proper syntax for using AddAttachment with an INPUT of type 'file'? I need a way to validate that the file the user is selecting is valid, but more importantly, I want to understand conceptually what I'm doing wrong.
Thanks In Advance,
---JC
_________________
---On a campaign for more examples and better docs! |
 |
 |
Benjamin Krajmalnik
|
| Posted: 09/07/2006, 8:27 PM |
|
The attachment needs to be a local file. I would add a file upload
component in the form to use as a mechanism of moving the file to the
server. After it has been uploaded, you can trigger your CDO code to attach
the local file. And after this has done, you can get rid of the file.
If you do not want to use the file upload component, the link below shows
almost how to do it - except is is using CDONTS.
http://www.motobit.com/tips/detpg_send-email-from-asp/
All you need to do is replace the CDONTS methods with the CDOOSYS ones.
"Suntower" <Suntower@forum.codecharge> wrote in message
news:644feec81456ee@news.codecharge.com...
> I have a typical form for sending an e-mail. There is an INPUT<> for
> adding an
> attachment. But it appears there is something I am not understanding about
> VB
> syntax
>
> In the onclick event for the 'submit' button...
>
> DIM MyAttachment
> DIM MailerObj
> MyAttachment = NewRecord.TextBox1.Value 'This is the
> attachment
> field
>
>
> 'Send message to Distributor
> Set MailerObj =Server.CreateObject("CDO.Message")
> MailerObj.From = Session("GLO_Server_EmailFromAddress")
> MailerObj.To = Session("GLO_Server_General_EmailToAddress")
> MailerObj.Subject= NewRecord.MessageSubject.Value
> MailerObj.TextBody=NewRecord.MessageBody.Value
> IF rtrim(MyAttachment) <> "" THEN
> MailerObj.AddAttachment MyAttachment
> END IF
> MailerObj.Send
>
> OK. If I use a regular text input field, this will work (so long as the
> filename in the field is absolutely correct, of course.) HOWEVER, if I
> change
> the INPUT<> to type 'file', this doesn't work. What happens is that there
> is
> either an ASP error -or- the e-mail gets sent but the attachment is
> completely
> wrong---it's an empty file named like the subject line.
>
> How come? What -is- the proper syntax for using AddAttachment with an
> INPUT of
> type 'file'? I need a way to validate that the file the user is selecting
> is
> valid, but more importantly, I want to understand conceptually what I'm
> doing
> wrong.
>
> Thanks In Advance,
>
> ---JC
>
>
>
>
>
>
>
>
> _________________
> ---On a campaign for more examples and better docs!
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>
|
|
|
 |
|