ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / Developing an application or website / Controls, windows and pages / Controls: Available types / Rich Text Area control
  • 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
Email.Sender = "<user@windev.com>" // Sender
Email.Recipient[1] = RECIPIENT // Recipient
Email.NbRecipient = 1 // Number of recipients
Email.Subject = SUBJECT // Subject
Email.Message = TEXT // Message body
Email.NbAttach = 0 // Number of attachments
// 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 uses 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
gSMTPSession is emailSMTPSession
gSMTPSession.ServerAddress = "smtp.gmail.com"
gSMTPSession.Name = gsUser
gSMTPSession.Password = gsPassword
gSMTPSession.Port = 587
gSMTPSession.Option = emailProtocolSMTPS

// 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(gSMTPSession) = True THEN
	IF EmailSendMessage(gSMTPSession, 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: 03/25/2025

Send a report | Local help