emRetrieveMail()

The function connects to a POP3 server and checks wether there are mails. If there are, the function retrieves the mails and deletes the mail at the server.

Using the function emRetrieveMail() in a CTRL-Script, you have to insert the following entry in the config.level of your project before starting the Control Manager:

[ctrl]LoadCtrlLibs = "email.ctl"

Synopsis

int emRetrieveMail (string pop3_host, string user, string passwd, dyn_dyn_string &emails);

Parameters

Parameter Meaning
pop3_host Host name (IP Address) of the POP3 Server
name User name of the email accounts at the POP3 Server
passwd Password of the user
&emails

The dyn_dyn_string email returns the received mails. The first index is the number of the mail , the second index represents either of the following:

email[1][1] .... Receiver

email[1][2] .... Sender

email[1][3] .... Subject

email[1][4] .... Message Body

Return value

The function returns the number of emails or in case of errors, -1

Error

In the case on an error, an internal error message will be displayed.

Description

The function connects to a POP3 Server and collects the mails based on a POP3 protocol. The mails at the server will be deleted.

When the subject or the message body contain German umlauts, these will be converted in the receiver subject/message, e.g. ä -> ae or ö -> oe. However, arbitrary coded information (e.g. MIME) can be passed to the function directly. For example
email_cont[4] = "=?ISO-8859-1?Q?=F6=E4=FC?="
will be converted to "öäü".

You have to load the script email.ctl, and make an entry in the [ui] and [ctrl] section of the config.level file: LoadCtrlLibs = "email.ctl".

A maximum of five mails can be retrieved and deleted with one function call.

Do not start Outlook when using the function, because Outlook uses the same functions and could be faster.

Example

main()
{
  int i,num;
  string sender, receiver, headline, message;
  string password;
  dyn_dyn_string emails;
  password = TextField1.text; //edit password in text field
  emRetrieveMail ("prj1", "username", password, emails);
  num = dynlen(emails); // Number of mails at POP3 server
  for(i=1;i<=num;i++) // retrieving the mails
  {
    sender = emails[i][1];
    receiver = emails[i][2];
    headline = emails[i][3];
    message = emails[i][4];
    DebugN("Sender:",sender);
    DebugN("Receiver: ",receiver);
    DebugN("Headline": ",headline);
    DebugN("Message:",message);
  }
}

Assignment

Communication functions

Availability

CTRL