Skip to content

MvPOP#


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 to delete the message and to terminate the loop.

Syntax
<MvPOP MAILHOST = "string: {  expression } | literal"
       LOGIN = "string: {  expression } | literal"
       PASSWORD = "{ expression } | literal"
       DIRECTORY = "string: {  expression } | literal">

       <MvPOPDELETE>
       <MvPOPSTOP>
       <MvPOPCONTINUE> 
</MvPOP>

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#

Attribute Description
MAILHOST Required domain name or IP address of an email host that understands POP3
LOGIN Required. The user name for the email account.
PASSWORD Required. The password for the email account.
DIRECTORY Required. The path within the mivadata folder where the email will be stored.

When <MvPOP> retrieves an email message, it stores information about the message in several special variables:

  • messagesubject: The ‘Subject:’ line of the incoming message.
  • messagedate: The ‘Date:’ line of the message.
  • messagesender: The ‘From:’ line (sender) of the message. Do not use this value for replying to a message; instead, use the value of messagereplyto.
  • messagereplyto: The ‘Reply-To:’ line (the address to which replies should be sent). If the incoming message does not have ‘Reply-To’ in its header, then the ‘From:’ line is used for this value.
  • messagebody: A guaranteed unique file name in which the message body has been saved.

Some or all of the first four values in the list may be unavailable if the message header is missing or truncated.

Example#

This 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.

<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>
Output
You received mail from: Walter Mitty.<br>
This mail is about: My latest adventures.<br>
This mail was received on: Tue, 10 Mar 2000 13:50:10 -0500 (EST).<br>
I stored this mail in the file: mymail/MIVA_POP.a06431.<br>
You can reply to: 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 Message#

By 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.

<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>