|
Logs into the POP3 mail server named host, using the login_name and password login information, and retrieves all incoming mail messages in a loop, one message at a time. Use
Miva Script provides tags that can send and receive email. <MvSMTP> is used to send mail from any valid SMTP mail server, and Miva Script documents can receive email by becoming POP3 clients using <MvPOP> <MvPOP> creates a loop that logs into the POP3 mail server host, using a login name and password, and retrieves all incoming mail messages, one message at a time. Messages can be stored on your local system (that is, the system running Miva Script, not necessarily the system running the POP3 server) under unique filenames, in the directory specified with DIRECTORY. The host, login name, password, and storage directory are all required. When a message is retrieved, information about the message is stored in the special variables messagebody, messagesubject, messagereplyto, messagesender, and messagedate. This information can then be processed inside the loop. If an optional <MvPOPDELETE> tag is executed, the current message is deleted from the server. If an optional <MvPOPSTOP> is executed, the <MvPOP> loop terminates. Attributes
When <MvPOP> retrieves an email message, it stores information about the message in several special variables:
Some or all of the first four values in the list may be unavailable if the message header is missing or truncated. ExamplesThis code reads incoming email messages belonging to the user my_userid, who has the password pa55w0rd, on the mail server mail.my_isp.com; these messages are stored in a directory called mymail. Example:<MvPOP MAILHOST="mail.my_isp.com" LOGIN="my_userid" PASSWORD="pa55w0rd" DIRECTORY="mymail"> <p>You received mail from: <MvEVAL EXPR="{messagesender}">.<br> This mail is about: <MvEVAL EXPR="{messagesubject}">.<br> This mail was sent on: <MvEVAL EXPR="{messagedate}">.<br> I stored this mail in the file: <MvEVAL EXPR="{messagebody}">.<br> You can reply to: <MvEVAL EXPR="{messagereplyto}">. </p> </MvPOP> Here is a sample of the output. You received mail from: Walter Mitty. Note: The storage directory should be specified as a directory relative to the data directory of the owner of the active document if Miva Merchant Empresa is running in server-safe (multi-user) mode; it can be a relative or absolute path if Miva Merchant Empresa is running in standard mode. If there is more than one incoming message, <MvPOP> will iterate through them and print these fields for each message. Deleting an Email MessageBy default, <MvPOP> does not remove email messages from the POP3 server. If you want to remove a message, you need to execute an <MvPOPDELETE> tag inside the <MvPOP> loop. This deletes the current email message on the server. The message will still be processed by the application in this iteration of the <MvPOP> loop. Make sure you delete the temp email files periodically or they will continue to accumulate. This example returns and deletes a single message for the email host server, loads and displays the message file. Example:<MvPOP MAILHOST="mail.my_isp.com" LOGIN="my_userid" PASSWORD="pa55w0rd" DIRECTORY="mymail"> <MvPOPDELETE> <MvPOPSTOP> </MvPOP> <p> Subject: <b><MvEVAL EXPR="{messagesubject}"><b><hr> From: <MvEVAL EXPR="{messagesender}"> -- Date: <MvEVAL EXPR="{messagedate}"><br> Reply to: <MvEVAL EXPR="{messagereplyto}"><br> <br> <MvCOMMENT> Display the message and delete the file. </MvCOMMENT> <MvASSIGN NAME="g.size" VALUE="{ file_read(messagebody, 'data', g.message) }"> <MvEVAL EXPR="{ g.message }"> <MvASSIGN NAME="g.ok" VALUE="{ fdelete(messagebody) }"> </p>
|