PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Principle
  • Step 1: Creating a user account in the application for email management
  • Creating an account
  • Step 2: Starting an email session
  • Example
  • Step 3: Sending and receiving emails
  • Sending emails
  • Receiving emails
  • Step 4: Closing the session
  • Example
  • Step 5: Synchronizing the emails with the email server
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
Principle
To send or read emails via the user accounts other than the "ActiveSync" account of Pocket Outlook, you must:
  1. Describe a user account in the application for email management (Pocket Outlook for example).
  2. From the WINDEV Mobile application, connect to the application for email management (Pocket Outlook for example) by using EmailStartSession associated with a emailOutlookSession variable (or with EmailStartOutlookSession).
  3. Send and receive the emails.
  4. Close the session to the application for email management (Pocket Outlook for example) with EmailCloseSession.
  5. Synchronize the emails with the email server.
Step 1: Creating a user account in the application for email management
The user account allows you to configure the application for email management (Pocket Outlook for example).
The following elements are defined in the user account:
  • the parameters of SMTP protocol used to send messages,
  • the parameters of POP3 or IMAP protocol used to receive messages,
  • the different communication services used.
Note: An account must be created for each different user or email account. The account name will be used to start the email session.

Creating an account

To create an account (in Pocket Outlook for example):
  1. Start Pocket Outlook ("Start .. Programs .. Inbox" for example).
  2. Select "Accounts .. New account" (or "Services .. New services").
  3. Answer the questions.
  4. Give a name to the account: this name will be used in the WINDEV Mobile programs.
Step 2: Starting an email session
Starting an email session can be performed by:
Note: This function must be called before any other "email" function in your application.

Example

Starting a session with an emailOutlookSession variable
PROCEDURE StartSession (AccountName)

MySession is EmailOutlookSession
MySession..Name = AccountName

EmailStartSession(MySession)
IF ErrorOccurred = True THEN
Error("The session cannot be started." + ...
"Error:" + CR + ErrorInfo(errMessage))
END
RESULT MySession
Starting a session with StartOutlookSession
PROCEDURE StartSession (AccountName)

SessionNum is int
SessionNum = EmailStartSession(Account)

IF SessionNum = 0 THEN
Error("The session cannot be started." + ...
"Error:" + CR + ErrorInfo(errMessage))
END

RESULT SessionNum
Step 3: Sending and receiving emails

Sending emails

  • If the Pocket PC is connected to a PC, the emails are automatically sent when the Pocket PC is connected to a PC equipped with an Internet access.
  • If the Pocket PC is not connected to a PC (the Pocket PC is equipped with an Ethernet card or a GPRS modem), the emails are sent by EmailSendMessage: this function is used to place the message in the outbox of the application for email management (outbox of Pocket Outlook for example).
See Preparing to send an email for more details.
Example: The following code is used to send all the emails found in a memory table ("TABLE_TOSEND" table) via Pocket Outlook. Each table row corresponds to an email.
For each email, the information found in the memory table is transferred into the email structure and the email is sent. Then, the email server is updated.
I is int
FOR I = 1 _TO_ TableCount(TABLE_TOSEND)
// The email is sent to a single person
Email.NbRecipient = 1
Email.Recipient[1] = ExtractString(TABLE_TOSEND[I], 1)
// Subject and message
Email.Subject = ExtractString(TABLE_TOSEND[I], 2)
Email.Message = ExtractString(TABLE_TOSEND[I], 3)
// No attached file
Email.NbAttach = 0
// Send the message to Pocket Outlook
EmailSendMessage(SessionNum, False)
END

Receiving emails

  • If the Pocket PC is connected to a PC, the emails are automatically received when the Pocket PC is connected to a PC equipped with an Internet access.
  • If the Pocket PC is not connected to a PC (the Pocket PC is equipped with an Ethernet card or with a GPRS modem), the emails are received via the functions for reading emails (EmailReadFirst, EmailReadNext, etc.): these functions are used to initialize the email structure of WLanguage with the characteristics of the email currently read (sender, subject, etc.).
See Reading an email for more details.
Example: The following code is used to read the emails. The incoming emails are stored in a memory table ("TABLE_Messages"). The SessionNum variable corresponds to the identifier of the session. In this example, the incoming messages are deleted from the inbox and from the email server by EmailDeleteMessage.
// Read the first unread message
IF EmailReadFirst(SessionNum ,"UNREAD") = False THEN
Error("Error while reading the first message")
END

// Browse the unread messages and display them in a memory table
TableDeleteAll(TABLE_Messages)
WHILE NOT Email.Out
// The reception date, the sender's address
// and the message are assigned to the table
TableAdd(TABLE_Messages, Email.ReceiveDate + TAB + Email.SenderAddress + ...
TAB + Email.Message)
// Delete the message
IF EmailDeleteMessage(SessionNum) = False THEN
Error("Error during the deletion" + ...
"The message was not deleted")
END
// Read the next unread message
IF EmailReadNext(SessionNum,"UNREAD") = False THEN
Error("Error while reading the next message")
END
END
Step 4: Closing the session
When the management of incoming and outgoing emails is completed, the session is closed by EmailCloseSession. This function must be the last "email" function used.

Example

The following code is a procedure used to close an email session. In this code, the SessionNum variable corresponds to the session identifier returned by EmailStartSession.
PROCEDURE CloseSession(SessionNum)
// Close the session
EmailCloseSession(SessionNum)
Step 5: Synchronizing the emails with the email server
Once the email session has been closed, the emails must be synchronized with the email server. To do so, start Pocket Outlook if necessary and select "Service .. Connect".
If the Pocket PC is not equipped with an Ethernet card or a GPRS modem, the Pocket PC must be connected to a PC to actually synchronize the emails.
No specific setting is required in ActiveSync.
Minimum required version
  • Version 9
Comments
Click [Add] to post a comment