Svar:
w3 JMail komponentet giver mulighed for at sende og læse e-mail via ASP. De to eksempler nedenfor viser henholdsvis hvordan en e-mail sendes via w3 JMail, og hvordan en e-mail læses. Begge scripts skal placeres i roden af websitet, og vedhæftede filer for eks. 2 bliver gemt i "/log/" mappen.
Bemærk: Funktioner, der gør brug af MS Pickup Directory (MS SMTP Service) eller PGP kryptering, er ikke understøttet.
Download eks.: w3JMail1.zip (SMTP)
Download eks.: w3JMail2.zip (POP3)
Det kan anbefales at downloade en demo version af dette komponent for at teste ASP scripts lokalt, inden de køres på webserveren.
Download w3 JMail
Eksempel for SMTP:
<html>
<head>
<title>w3 JMail SMTP Demo Script</title>
<head>
<body bgcolor="white">
<blockquote>
<h2>w3 JMail SMTP Demo Script</h2>
<%
Set msg = Server.CreateOBject( "JMail.Message" )
msg.Logging = True
msg.Silent = True
msg.From = "afsender@domain.dk"
msg.FromName = "Realname"
msg.Charset = "iso-8859-1"
msg.AddRecipient "modtager@domain.dk", "Realname"
msg.Subject = "How you doin?"
msg.Body = "Hello Jim" & vbCrLf & vbCrLf & "How's it going? ..."
if not msg.Send("small.massmail.scannet.dk" ) then
Response.write "<pre>" & msg.log & "</pre>"
else
Response.write "Message sent succesfully!"
end if
Set msg = nothing
%>
<blockquote>
</body>
</html>
Eksempel for POP3:
<html>
<head>
<title>w3 JMail POP3 Demo Script</title>
<head>
<body bgcolor="white">
<blockquote>
<h2>w3 JMail POP3 Demo Script</h2>
<%
Set pop3 = Server.CreateObject("JMail.POP3")
pop3.Connect "username/mailserver", "password", "mailserver"
Response.Write( "You have " & pop3.count & " emails in your mailbox!<br><br>" )
if pop3.count > 0 then
Set msg = pop3.Messages.item(1)
' Note the first element of this array is 1,
' since the POP3 server starts counting at 1
ReTo = ""
ReCC = ""
Set Recipients = msg.Recipients
separator = ", "
' We now need to get all the recipients,
' both normal and Carbon Copy (CC) recipients
' and store them in a variabel
for i = 0 To Recipients.Count - 1
if i = Recipients.Count - 1 then
separator = ""
end if
Set re = Recipients.item(i)
if re.ReType = 0 then
ReTo = ReTo & re.Name & " (" & re.EMail & ")" & separator
else
ReCC = ReTo & re.Name & " (" & re.EMail & ")" & separator
end if
next
' This function iterates through the Attachments object,
' and saves the attachment to the server's disk.
' It also returns a nicely formatted string with a
' link to the attachment.
Function getAttachments()
Set Attachments = msg.Attachments
separator = ", "
for i = 0 To Attachments.Count - 1
if i = Attachments.Count - 1 then
separator = ""
end if
Set at = Attachments(i)
at.SaveToFile(""&Request.ServerVariables("APPL_PHYSICAL_PATH")&"\log\"&at.Name&"")
getAttachments = getAttachments & "<a href=""/log/" &_
at.Name &""">" & at.Name & "(" & at.Size & " bytes)" &_
"</a>" & separator
next
End Function
Response.Write "<table>" + vbCrLf
Response.Write "<tr><td>Subject</td><td>"&msg.Subject&"</td></tr>" + vbCrLf
Response.Write "<tr><td>From</td><td>"&msg.FromName&"</td></tr>" + vbCrLf
Response.Write "<tr><td>Recipients To</td><td>"&ReTO&"</td></tr>" + vbCrLf
Response.Write "<tr><td>Recipients CC</td><td>"&ReCC&"</td></tr>" + vbCrLf
Response.Write "<tr><td>Attachments</td><td>"&getAttachments&"</td></tr>" + vbCrLf
Response.Write "<tr><td>Body</td><td><pre>"&msg.Body&"</pre></td></tr>" + vbCrLf
Response.Write "</table>" + vbCrLf
end if
pop3.Disconnect
Set pop3 = nothing
%>
</blockquote>
</body>
</html>
Se den komplette dokumentation.
Hvordan ville du karakteriserer dette indhold (hvor 5 er bedst)?