/ Forside / Teknologi / Udvikling / ASP / Nyhedsindlæg
Login
Glemt dit kodeord?
Brugernavn

Kodeord


Reklame
Top 10 brugere
ASP
#NavnPoint
smorch 9259
Harlekin 1866
molokyle 1040
Steffanst.. 758
gandalf 657
smilly 564
gibson 560
cumano 530
MouseKeep.. 480
10  Random 410
JMail med vedhæftfil
Fra : Rune Thougaard Krist~


Dato : 25-09-03 12:31

Hvordan laver jeg en JMail komponent som også kan sende vedhæftede filer. ?

mvh. Rune Thougaard
--



 
 
mcfritten (31-10-2003)
Kommentar
Fra : mcfritten


Dato : 31-10-03 11:52

Rune Thougaard Kristensen wrote in dk.edb.internet.webdesign.serverside.asp:
> Hvordan laver jeg en JMail komponent som også kan sende vedhæftede filer. ?
>
> mvh. Rune Thougaard
> --
>
Dette her er hentet fra http://dimac.net egen side så kn du selv rette den
til, så den passer til dig:

Attachments
Attaching files to your w3 JMail emails requires that the file you wish to
attach resides on the webserver. However, using w3 Upload, you can let the
user upload the file to the webserver and attach it on the fly. Check out the
samples below to find out more...



First of all we a form where the user can enter his email message and select
which file to attach.


JMailUpload.asp
<html>
<head>
<title>emailform</title>
</head>
<body>
<font face="verdana, arial" size="2"><b>
<form method="post" action="JmailUploadProcess.asp"
ENCTYPE="multipart/form-data">
Complete this form and click the submit-button. We will answer your
questions as soon as possible.
<br><br>
Your name <br>
<input type="text" size="25" name="name"><br>

Your email <br>
<input type="text" size= "25" name= "email"><br>< /FONT>

Recipient email <br>
<input type= "text" size= "25" name= "recipient"><br>< /FONT>

State your business <br>
<select name="subject" size="1">
<option value="help">help
<option value="tips">tips
<option value="other">other
</select>
<br>

Enter your question <br>
<textarea name="body" cols="40" rows="15" wrap="PHYSICAL"></textarea>
<br>

Attachments <br>
<input type="file" name="attachment">
<br>
<br>
<input type="submit" value=" Submit ">
</form>
</b></font>
</body>
</html>

Okay, Now lets put all that info into our email. Again, notice how we use the
Upload object instead of the Request object.


JMailUploadProcess.asp

<%@LANGUAGE="VBSCRIPT" %>
<HTML>
<BODY>
<%
' Create the JMail message Object
set msg = Server.CreateOBject( "JMail.Message" )
Set upload = Server.CreateObject( "w3.Upload" )

' Check for attachments and add them to the email
set attachment = upload.Form( "attachment" )
if attachment.IsFile then
msg.AddCustomAttachment attachment.filename, attachment.item, false
end if

' Set logging to true to ease any potential debugging
' And set silent to true as we wish to handle our errors ourself
msg.Logging = true
msg.silent = true

' Get the form variables, using the upload object
Name = upload.Form("name")
SenderEmail = upload.Form("email")
Subject = "Regarding " & upload.Form ("subject")
Recipient = upload.Form("recipient")
Body = upload.Form("body")

' And apply them to the message
msg.From = SenderEmail
msg.FromName = Name

msg.AddRecipient Recipient
msg.Subject = Subject

msg.Body = Body

' To capture any errors which might occur, we wrap the call in an IF statement
if not msg.Send( "mail.myDomain.net" ) then
Response.write "<pre>" & msg.log & "</pre>"
else
Response.write "Message sent succesfully!"
end if


' And we're done! the message has been sent.
%>
</BODY>
</HTML>








There you go! Notice how w3 Upload never actually saves the file to your disc,
but rather just attaches the file to the email. Quite nifty as your webserver
wont get cluttered with files.



--
Vil du lære at kode HTML, XHTML, CSS, SSI eller ASP?
- Pædagogiske tutorials på dansk
- Kom godt i gang med koderne
KLIK HER! => http://www.html.dk/tutorials

Søg
Reklame
Statistik
Spørgsmål : 177551
Tips : 31968
Nyheder : 719565
Indlæg : 6408824
Brugere : 218887

Månedens bedste
Årets bedste
Sidste års bedste