20.8.1 Use a browser's built in support for sending email

The simplest way to send an email is by using the browser's built in support of the mailto attribute on a hyperlink.

Define_Com Class(#PRIM_PHBN) Name(#Send) Caption('Send') Parent(#COM_OWNER) Width(109) Height(114)

 

Define_Com Class(#prim_alph) Name(#Mailto)

Define_Com Class(#prim_alph) Name(#Parameters)

 

Evtroutine Handling(#Com_owner.Initialize)

 

#To := "Sample@_YourSite_.Com"

#CC := "CC_Sample@_YourSite_.Com"

#BCC := "BCC_Sample@_YourSite_.Com"

#Subject := "Sample subject"

#Message := "Sample message content."

 

Endroutine

 

Evtroutine Handling(#Send.Click)

 

#Com_owner.MailTo

 

Endroutine

 

Mthroutine Name(MailTo)

 

#Mailto := ("mailto:&1").Substitute( #To )

 

#Com_owner.Addparameter( CC #CC )

#Com_owner.Addparameter( BCC #BCC )

#Com_owner.Addparameter( Subject #Subject )

#Com_owner.Addparameter( Body #Message )

 

#sys_web.navigate( (#Mailto + #Parameters) current )

 

Endroutine

 

Mthroutine Name(AddParameter) Access(*Private)

Define_Map For(*Input) Class(#xDemoUnicode128) Name(#Name)

Define_Map For(*Input) Class(#xDemoUnicode4K) Name(#Value)

 

If (#Parameters = "")

#Parameters := "?"

Endif

 

If (#Parameters <> "?")

#Parameters += "&"

Endif

 

If (#Value = "")

#Value := "???"

Endif

 

#Parameters += ("&1=&2").Substitute( #Name #Value.ReplaceAll( " " "%20" ) )

 

Endroutine

In this example the URL provided for the SYS_WEB.navigate would have a value of:

Note: URLs have strict syntactic rules and do not support blank spaces. To embed characters that are not included in the ASCII subset supported by URLs, you need to percent encode the character in question. The byte x20 represents a blank in ASCII encoding hence the percent encoding value is %20. For more Percent Encoded values refer to HTML URL Encoding Reference.

When the mailto attribute is used the browser knows to open the default email program and sets the address and other parameters as specified in the link.

Advantages

This is easy to implement and widely supported.

Disadvantages

As processing is on the client side, spam bots can pick up the email address listed on the page (although there are ways to protect against this) and users can see where the email is being sent to.

In addition, not all user pcs will be correctly configured with a supported email default application.