Forum de discussion
Forum « Programmation ASP » (archives)
Re: Interogation d'un serveur pop
Envoyé: 10 septembre 2003, 12h53 par Oznog
Tu va devoir installer une composante sur ton serveur :
' La composante "EasyMail Objects 6.0" (http://www.quiksoft.com/objects/)
Set POP3 = CreateObject("EasyMail.POP3.6")
POP3.MailServer = "mail.yourdomain.com"
POP3.Account="jdoe"
POP3.Password="secret"
pop3.Connect
x = POP3.DownloadMessages(0)
if x = 0 then
msgbox "You have" &
POP3.Messages.Count &
"messages waiting."
else
msgbox "There was an error
retrieving your mail. Error code: " & x
end if
POP3.Disconnect
-------------------------------------
' La composante "AspPOP3 2.x" (http://www.serverobjects.com/products.htm#AspPop3)
Set Mailer = Server.CreateObject("POP3svg.Mailer")
Mailer.RemoteHost = "mailhost.localisp.net"
Mailer.UserName = "myname"
Mailer.Password = "mypassword"
Mailer.MailDirectory = "d:\usermail\myname"
Mailer.OpenPop3
Mailer.MailDirectory = "d:\usermail\myname"
Mailer.RetrieveToFile 1, "1.txt"
Mailer.ClosePop3
-------------------------------------
'La composante "w3 JMail v4.3" (http://www.dimac.net/)
<% @LANGUAGE=VBSCRIPT %>
<%
Set pop3 = Server.CreateObject( "JMail.POP3" )
pop3.Connect "username", "password", "mail.mydomain.com"
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( "c:\attachments\" & at.Name )
getAttachments = getAttachments & "<a href=""/attachments/" &_
at.Name &""">" & at.Name & "(" & at.Size & " bytes)" &_
"</a>" & separator
Next
End Function
%>
<html>
<body>
<TABLE>
<tr>
<td>Subject</td>
<td><%= msg.Subject %></td>
</tr>
<tr>
<td>From</td>
<td><%= msg.FromName %></td>
</tr>
<tr>
<td>Recipients To</td>
<td><%= ReTO %></td>
</tr>
<tr>
<td>Recipients CC</td>
<td><%= ReCC %></td>
</tr>
<tr>
<td>Attachments</td>
<td><%= getAttachments %></td>
</tr>
<tr>
<td>Body</td>
<td><pre><%= msg.Body %></pre></td>
</tr>
</TABLE>
</body>
</html>
<%
end if
pop3.Disconnect
%>
-----------------------------
La composante .NET "SoftArtisans POP3" (http://www.softartisans.com/pop3.html)
Etc...
TON EXEMPLE :
On retrouve plusieurs scripts utilisant la composante CDO pour lire un compte POP mais j'ai bien peur que cela demande une configuration tout à fait spéciale et surtout des "Usagers connus" du réseau et non pas des "Visiteurs du Web".
Avec "session" comme ton exemple et si le serveur est configuré pour ça "ListMesMessages.count" devrait te retourner le nombre de courriel. Mais tu aura probablement le message d'erreur : "Permission denied".
La session mais aussi le chemin d'accès avec le "directory"...
Set objDropDirectory = CreateObject("CDO.DropDirectory")
strDropDirectory = "c:\Inetpub\mailroot\Cie\Drop"
Pour plus d'information avec CDO voir http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cdosys/html/_cdosys_reference.asp
Ciao
Oznog
Réponses
|