Classic ASP
Classic ASP
Copy an Email from One Mailbox to Another
Copies an email from one IMAP folder to another. After running this example, copies of the email will be present in both source and destination folders.Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
' This example requires the Chilkat API to have been previously unlocked.
' See Global Unlock Sample for sample code.
' This example copies an email from one mailbox to another.
set imap = Server.CreateObject("Chilkat.Imap")
' Turn on session logging:
imap.KeepSessionLog = 1
' Connect to an IMAP server.
' Use TLS
imap.Ssl = 1
imap.Port = 993
success = imap.Connect("imap.example.com")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( imap.LastErrorText) & "</pre>"
Response.End
End If
' Login
success = imap.Login("***","***")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( imap.LastErrorText) & "</pre>"
Response.End
End If
' Select an IMAP mailbox
success = imap.SelectMailbox("Inbox.testing.a")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( imap.LastErrorText) & "</pre>"
Response.End
End If
fetchUids = 1
' Get the message IDs for all emails having "Re:" in the subject.
set messageSet = Server.CreateObject("Chilkat.MessageSet")
success = imap.QueryMbx("SUBJECT Re:",fetchUids,messageSet)
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( imap.LastErrorText) & "</pre>"
Response.End
End If
' Copy the messages from "Inbox.testing.a" to "Inbox.testing.b" in one call to CopyMultiple:
success = imap.CopyMultiple(messageSet,"Inbox.testing.b")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( imap.LastErrorText) & "</pre>"
Response.End
End If
' Alternatively, loop over each message in the set and
' copy each separately:
i = 0
Do While i < messageSet.Count
msgId = messageSet.GetId(i)
isUid = messageSet.HasUids
success = imap.Copy(msgId,isUid,"Inbox.testing.c")
If (success = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( imap.LastErrorText) & "</pre>"
Response.End
End If
i = i + 1
Loop
' Display the session log.
Response.Write "<pre>" & Server.HTMLEncode( imap.SessionLog) & "</pre>"
' Disconnect from the IMAP server.
success = imap.Disconnect()
%>
</body>
</html>