AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Comunicación / Gestión de correos electrónicos
  • Principle
  • Steps to follow
  • Writing an email with an Email variable
  • Writing an email with the Email structure
  • Examples
  • Example that uses EmailImportHTML
  • Example that uses the Email structure
  • Using the EML format to customize emails
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
Principle
Two methods can be used to manage the emails in WLanguage:
  • the Email structure, which allows you to easily handle messages.
    In this case, to write an email, you must use the different variables of Email structure.
  • the advanced Email type, which offers advanced functionalities (data binding, serialization, multiple instances, etc.).
    In this case, to write an email, you must declare and initialize a variable of type Email. The possible attachments will be declared in the emailAttach variables and added to the Attach property of the Email variable.
When sending the message (EmailSendMessage), the data found in the email variable or structure will constitute the outgoing message.
Steps to follow

Writing an email with an Email variable

To write an email with an Email variable:
  1. Declare and initialize a variable of type Email by specifying the recipients and subject with the Recipient, Cc, Bcc and Subject properties, for example.
    To manage a conversation follow-up, specify the MessageID property as well.
  2. If the email is in text format:
    • Initialize the Message property with the text of the email.
    • Specify the attached files if necessary by declaring variables of type emailAttach and adding them to the Attach property of the variable representing the email.
  3. If the Email is in HTML format format, use the EmailImportHTML function to initialize the various properties of the Email. If the email contains images or media files, they will be automatically added in attachment and the content of HTML email will be modified to support the attachments.
  4. Specify additional headers if necessary via the Header property.
  5. Send the email with EmailSendMessage. If the subject (or one of the email elements) contains special characters or accented characters, use the emailOptionEncodeHeader constant when the message is sent by EmailSendMessage. The email is sent to the server. The server stores the email until the session is closed. During this closing, the email is actually sent to the recipients.

Writing an email with the Email structure

To write an email with the Email structure:
  1. Initialize the Email structure by specifying the recipients and subject with the Email.Recipient, Email.NbRecipient, Email.NbCc, Email.Cc and Email.Subject variables, for example.
    To follow the progress of conversion, fill Email.MessageID.
  2. If the email is in HTML format:
    • 1st case: the EmailImportHTML function is available:
      • Use EmailImportHTML to initialize the different variables of Email structure.
    • 2nd case: the EmailImportHTML function is not available:
      • Initialize the Email.Message and Email.HTML variables.
        Note: For e-mail systems that cannot read HTML-formatted e-mails, it is advisable to set the message in text format.
      • Analyze the HTML message to detect all media files included in the message.
      • For each media file found:
        • Create an attached file. This attached file corresponds to the media file (Email.Attach and Email.NbAttach variables).
        • Create an identifier (Email.AttachIdentifier). This identifier must have the following format "wdcid"+number of attached file. For example, WDCID5 if the corresponding file is the fifth attached file.
        • Find the multimedia file in the HTML message and replace its name with the string: "cid: "+Email.AttachID.
          For example:
          Original HTML code: <IMG src="C:\MesImages\Image.gif">
          HTML code replaced: <IMG src="cid:WDCID5">
  3. Send the email with EmailSendMessage.
    Note: If the subject (or any element of the Email) contains special characters or accents, use the constant emailOptionEncodeHead when sending the message with the EmailSendMessage function.
Examples
WEBDEV - Código ServidorWindowsLinux

Example that uses EmailImportHTML

This example is used to send an email containing images:
// Start an SMTP session
MySession is emailSMTPSession
MySession.ServerAddress = "smtp.mycompany.com"
EmailStartSession(MySession)
// Build the message
MyHTMLText is TO string
MyMessage is Email
MyHTMLText = fLoadText("C:\Email\MyEmail.htm")
EmailImportHTML(MyMessage, MyHTMLText, "C:\Email")
MyMessage.Recipient = "bob@mycompany.net"
MyMessage.Subject = "Test"
// Send the message
EmailSendMessage(MySession, MyMessage, emailOptionEncodeHeader)

Example that uses the Email structure

This example is used to replace the references to the media files (images, sounds, ...) found in the Email.HTML variable by their "CID" identifiers. This procedure is called for each file found.
PROCEDURE SetAttachFile(FileName, Subscript)
Email.Attach[Subscript] = FileName
Email.NbAttach ++
// Replace in Email.HTML all references to the attached files 
// by the cid identifier
CID is string = "cid:wdcid" + Subscript
// The HTML file was not necessarily created in the current directory
// It can reference the attached files in any path
// Therefore, extract the file name without path
SimpleName is string = fExtractPath(FileName, fFile + fExtension)
// Find the name of the file in Email.HTML
Pos is int = 0
StartPos, EndPos are int
SubString is string
Pos = Position(Email.HTML, SimpleName, Pos)
IF Pos <> 0 THEN
	EndPos = Pos + Length(SimpleName)
	// Find the start position of reference
	// Find the " marker
	Pos --
	SubString = Email.HTML[[Pos]]
	WHILE Pos > 1 AND SubString <> """"
	   Pos --
	   SubString = Email.HTML[[Pos]]
	END
	StartPos = Pos + 1
	// Replace
	SubString = Middle(Email.HTML, StartPos, EndPos - StartPos)
	Email.HTML = Replace(Email.HTML, SubString, CID)
END
Using the EML format to customize emails
WEBDEV - Código ServidorWindows In some cases, the structure of outgoing emails may not correspond to the requested information.
For example:
  • The communication with some organizations (emails for SESAM-VITALE) may require specific structures.
  • You may also want to use a specific character set (for a non-latin language).
  • You may want to specify a return address that differs from the sender address.
To customize these emails, WLanguage allows you to create the buffer of the email, to modify it and to send this email.
The following functions are used:
  • EmailImportSource: This functions is used to read an existing EML file and to automatically fill the variables of the Email structure.
  • EmailBuildSource: This function is used to generate the source code of an email. This function allows you to entirely define the source code of email by using the flexibility of Email structure.
  • EmailSend: This functions sends a "buffer" in EML format containing the structured email (created by EmailBuildSource for example).
Versión mínima requerida
  • Versión 9
Esta página también está disponible para…
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 27/03/2025

Señalar un error o enviar una sugerencia | Ayuda local