
Emails may be generated for sending on mobile devices using BrightForms. This is typically performed by specifying the fields such as the 'To' address via methods, then calling the Send() method of the email object. Typically, this call will open the device's native email client and configuration, populated with the fields configured in BrightForms, and is sent once the user sends it from this client.
Outside of this, emails may also be generated on BrightServer using a similar Email object and Scripts. For examples of server side email generation, please refer to the Email Examples topic in the Script Methods Reference chapter of this document.
Email.Reset();
Email.AddTo("test@example.com");
local.vResult = Email.Send("Subject", "Body");
Form.MessageBox("Email Sending", local.vResult, 0);
Note:
Email.Reset() is called to reset the email object. If not called, previously set values will be continued to be used if Send is called.
Email.AddTo() is used to set the primary address which will be used when Send() is called.
Email.Send() will send the email with the subject and body specified to the configured object values. On Windows and Windows Mobile, this will write the email in the device's outbox for sending. Outlook is required for this operation. On other devices, the method will open the device's email client with the specified fields populated.
The SetAccountName() method may be used to configure which email account to use to send the message, in the event multiple addresses exist on the device.
local.vResult – variable to store the return code of the send operation. A return code of 0 indicates success.
Email.Reset();
Email.AddTo("test@example.com");
Email.AddCc("test_cc@example.com");
Email.AddBcc("test_bcc@example.com");
local.vResult = Email.Send("Subject", "Body");
Form.MessageBox("Email Sending", local.vResult, 0);
Note:
Uses code similar to first example above for sending procedure
In addition to the 'to' address, CC and BCC addresses are also specified to send. Which will
//First, save the scribble as a JPG
local.vFile = System.GetProjectPath() & "/" & "filename.jpg";
scribbleControl.SaveJPEGFile(local.vFile);
//Proceed to send the email
Email.Reset();
Email.AddTo("test@example.com");
Email.AddAttachment(local.vFile);
local.vResult = Email.Send("Subject", "Body");
Form.MessageBox("Email Sending", local.vResult, 0);
Note:
Uses code similar to first example above for sending procedure to end the actual email.
scribbleControl - Scribble control on the form which is saved to a JPG via the SaveJPEFFile method, then attached to the email.
Attaches a file located on the device as an attachment via the AddAttachment method.
Email.Reset();
Email.SetFromAddress("user@example.com");
Email.SetFromName("Example Username");
Email.SetHost(mail.example.com);
Email.SetPort(25);
Email.AddTo("test@example.com");
local.vResult = Email.Send("Subject", "Body");
Form.MessageBox("Email Sending", local.vResult, 0);
Note:
Calling Email.Reset() will clear all email settings, along with SMTP configuration.Configures SMTP server and ports prior to sending the email, then proceeds to send the message.
Configuring the SMTP server also optionally allows the setting of the 'From' address and name.
Sending email via a host server is mandatory on BrightWeb to send emails successfully. It is optionally configurable on Android, and if configured, will bypass the compose message screen and send directly from the device (bypassing any email configurations on the device).
Email.Reset();
Email.SetProtocol("imap");
Email.SetEnableSSL(true);
Email.SetFromAddress("example.from.address@gmail.com");
Email.SetFromName("Example Username");
Email.SetHost(imap.gmail.com);
Email.SetPort(993);
Email.SetUserCredentials("example.from.address@gmail.com", "example.pass");
Email.AddTo("test@example.com");
local.vResult = Email.Send("Gmail IMAP (SSL)", "Body");
Form.MessageBox("Email Sending", local.vResult, 0);
Note:
Calling Email.Reset() will clear all email settings which were previously set.This example is similar to sending emails silently via SMTP above, but uses additional methods for authentication.
IMAP server is specified by the SetProtocol() method. If not used, BrightForms will default to SMTP.
The example above uses Gmail's IMAP server, authenticated with "example.from.address@gmail.com" username, and "example.pass" password. As the server requires an SSL connection on port 993, SetEnableSSL() is called (as it is set to false by default).
If additional properties need to be specified when sending the message, the SetProperty() method may be used. For example, if the authentication is via TLS instead of SSL, instead of SetEnableSSL(true), SetProperty("mail.smtp.starttls.enable","true") may be used.
If Email.Send() fails, the return code will be a non-zero integer. For more information regarding the error, please refer to BrightForms' ERROR log. With Gmail in particular, Google account settings may need to be adjusted, or application specific passwords may need to be generated to utilise certain types of connections.