PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

  • Example: Sending an email by using the SMTP protocol
  • Example: Sending an email via MS Exchange
  • Example: Sending an email via Pocket Outlook
  • Sending emails via a secure SMTP server
EmailSendMessage (Example)
Example: Sending an email by using the SMTP protocol
The following code is used to send an email by using the SMTP protocol. The characteristics of SMTP protocol have been specified by EmailStartSession (address of POP3 server, address of SMTP server, etc.).
IF EmailStartSession(USER, PASSWORD, "pop3.gmail.com", ...
"smtp.gmail.com") = True THEN
UserName = USER
ELSE
  UserName = ""
  Error("Unable to establish the connection")
END

// Initializes the email components
// The sender
Email.Sender = "<user@pcsoft.fr>"
// The recipient
Email.Recipient[1] = RECIPIENT
// The number of recipients
Email.NbRecipient = 1
// The subject
Email.Subject = SUBJECT
// The message body
Email.Message = TEXT
// The number of attachments
Email.NbAttach = 0

// Sends the email
IF EmailSendMessage(UserName) = False THEN
Error()
END
Example: Sending an email via MS Exchange
WINDEVWEBDEV - Server codeReports and QueriesWindowsAjaxUser code (UMC) The following code is using MS Exchange to send an email. A profile ("PROFILE_Example") was created in MS Exchange. See EmailStartSession for more details.
EmailID is int
EmailID = EmailStartSession("PROFILE_Example")

// Initialize the variables
Email.NbRecipient = 1
Email.Recipient[1] = "windev@windev.com"
Email.NbAttach = 0
Email.Message = ""

// Send the message to MS Exchange
EmailSendMessage(EmailID)
...
EmailUpdate(EmailID)
...
EmailCloseSession(EmailID)
Example: Sending an email via Pocket Outlook
Windows Mobile The following code is using Pocket Outlook to send an email. An account ("Example_Account") was created in Pocket Outlook. See the help page named Manage emails via CEMAPI: Other accounts for more details.
EmailID is int
EmailID = EmailStartSession("Example_Account")

// Initialize the variables
Email.NbRecipient = 1
Email.Recipient[1] = "windev@windev.com"
Email.NbAttach = 0
Email.Message = ""

// Send the message
EmailSendMessage(EmailID)
...
EmailCloseSession(EmailID)
Sending emails via a secure SMTP server
// Send emails via a secure SMTP server

// Secure SMTP session
gSessionSMTP is EmailSMTPSession
gSessionSMTP..ServerAddress = "smtp.gmail.com"
gSessionSMTP..Name = gsUser
gSessionSMTP..Password = gsPassword
gSessionSMTP..Port = 587
gSessionSMTP..Option = emailOptionSecuredTLS

// Email content    
AnEmail is Email
AnEmail..SenderAddress = gsUser
AnEmail..Recipient[1] = "pcsoft@windev.com"
AnEmail..Subject = "Sending an email from WINDEV."
AnEmail..Message = "Sending an email from WINDEV."

// Send the email
IF EmailStartSession(gSessionSMTP) = True THEN
IF EmailSendMessage(gSessionSMTP, AnEmail) = False THEN
Error("Failure sending the email.", ErrorInfo(errMessage))
END
ELSE
Error("Unable to establish the connection", ErrorInfo(errMessage))
END
Minimum required version
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment