ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Communication / Managing emails / WLanguage functions
  • Example: Sending an email using SMTP
  • Example: Sending an email via MS Exchange
  • Sending emails via a secure SMTP server
EmailSendMessage (Example)
Example: Sending an email using SMTP
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 QueriesWindowsUser code (UMC)Ajax The following code is using MS Exchange to send an email. A profile ("PROFILE_Example") was created in MS Exchange. For more details on how to create profiles, see EmailStartSession.
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)
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 version required
  • Version 9
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help