Skip to main content
Version: 8.1

Send email using the explicit account credentials

Level: advanced
Example

Create a business process that will open a page containing fields mapped to the email parameters to send an email using the explicit account credentials.

Example implementation algorithm

1. Create a business process

In the Configuration section execute the AddBusiness process action.

In the opened process designer set the following values for the properties in the setup area:

  • Title – "Sending emails using the explicit account credential".
  • Code – “UsrSendEmailWithCredentialsProcess.”

2. Add the Auto-generated page element

The Auto-generated page element enables the process to open an arbitrary page created by the user. For this element, add Filling parameters as a caption and set the following properties:

  • Page title – "Fill parameters for sending Email".
  • To whom should the page be shown? – select "Formula" and specify #System variable.Current user contact#.

3. Add a button to the page

To add a Continue button, click in the Buttons block and specify the following parameters:

  • Caption – "Continue".
  • Code – “ContinueButton.”
  • Style – select "Green".
  • Set the Active checkbox.
  • Set the Performs value validation checkbox.

Click Save.

4. Add elements to the page

To add an element that will contain the email sender’s mailbox, click in the Page Items block, select the Text field type and specify the following parameters:

  • Title – "Sender Mailbox".
  • Code – “SenderMailbox.”
  • Set the Required checkbox.

Click Save.

To add an element that will contain the name of the email sender, click in the Page Items block, select the Text field type and specify the following parameters:

  • Title – “User Name.”
  • Code – “UserName.”
  • Set the Required checkbox.

Click Save.

To add an element that will contain the password for email sender’s mailbox, click in the Page Items block, select the Text field type and specify the following parameters:

  • Title – “Password.”
  • Code – “Password.”
  • Set the Required checkbox.

Click Save.

To add an element that will contain the mail server address of the email sender, click in the Page Items block, select the Text field type and specify the following parameters:

  • Title – "Service Url".
  • Code – “ServiceUrl.”
  • Set the Required checkbox.

Click Save.

To add an element that will contain the port number of the email sender’s mail provider, click in the Page Items block, select the Integer type and specify the following parameters:

  • Title – “Port.”
  • Code – “Port.”

Click Save.

To add an element that will contain the cryptographic protocol to ensure a secure connection, click in the Page Items block, select the Boolean type and specify the following parameters:

  • Title – " Use Ssl".
  • Code – “UseSsl.”

Click Save.

To add an element that will contain the email recipient’s mailbox, click in the Page Items block, select the Text field type and specify the following parameters:

  • Title – "Recipient (many recipients separated by semicolon ";")".
  • Code – “Recipient.”
  • Set the Required checkbox.

Click Save.

To add an element that will contain the subject of the email, click in the Page Items block, select the Text field type and specify the following parameters:

  • Title – “Subject.”
  • Code – “Subject.”
  • Set the Required checkbox.

Click Save.

To add an element that will contain the body of the email, click in the Page Items block, select the Text field type and specify the following parameters:

  • Title – “Body.”
  • Code – “Body.”
  • Set the Required checkbox.

Click Save.

To add an element that will contain the type of the email sender’s provider, click in the Page Items block, select the Selection field type and specify the following parameters:

  • Title – "Type of mail server".
  • Code – “ServerTypeId.”
  • Set the Required checkbox.
  • Data source – select "Mail service provider type".
  • View – select "Drop down list".

Click Save.

5. Add a ScriptTask element

Set the value of the Title property of the Script task element to “Send Email.” The element must execute the following program code:

Script Task code
var emailClientFactory = ClassFactory.Get<EmailClientFactory>(new ConstructorArgument("userConnection", UserConnection));
var credentialConfig = new EmailContract.DTO.Credentials {
ServiceUrl = Get<string>("ServiceUrl"),
Port = Get<int>("Port"),
UseSsl = Get<bool>("UseSsl"),
UserName = Get<string>("UserName"),
Password = Get<string>("Password"),
ServerTypeId = Get<Guid>("ServerTypeId"),
SenderEmailAddress = Get<string>("SenderMailbox")
};
var emailSender = ClassFactory.Get<IEmailSender>(new ConstructorArgument("emailClientFactory", emailClientFactory),
new ConstructorArgument("userConnection", UserConnection));
var message = new EmailContract.DTO.Email {
Sender = credentialConfig.SenderEmailAddress,
Recepients = Get<string>("Recipient").Split(';').ToList<string>(),
Subject = Get<string>("Subject"),
Body = Get<string>("Body"),
Importance = EmailContract.EmailImportance.Normal,
IsHtmlBody = true,
// CopyRecepients = new List<string> { "user@mail.service" },
// BlindCopyRecepients = new List<string> { "user@mail.service" }
};
var attachment = new EmailContract.DTO.Attachment {
Id = Guid.NewGuid().ToString(),
Name = "test.txt",
};
byte[] data = Encoding.ASCII.GetBytes("some test text");
attachment.SetData(data);
message.Attachments.Add(attachment);
emailSender.Send(message, credentialConfig);
return true;

6. Add parameters

To add a business process parameter that will contain the address of the sender’s mail server, execute the Add parametersText action in the Parameters tab of the setup area and specify the following parameter properties:

  • Title – "Service Url".
  • Code – “ServiceUrl.”
  • Value – click Process parameter and select the “Service Url” process element.

Click Save.

To add a business process parameter that will contain the port number of the sender’s email provider, execute the Add parametersInteger action in the Parameters tab of the setup area and specify the following parameter properties:

  • Title – “Port.”
  • Code – “Port.”
  • Value – click Process parameter and select the “Port” process element.

Click Save.

To add a business process parameter that will contain the cryptographic protocol for a secure connection, execute the Add parametersBoolean action in the Parameters tab of the setup area and specify the following parameter properties:

  • Title – " Use Ssl".
  • Code – " UseSsl.”
  • Value – click Process parameter and select the “ Use SSL” process element.

Click Save.

To add a business process parameter that will contain the email sender’s name, execute the Add parametersText action in the Parameters tab of the setup area and specify the following parameter properties:

  • Title – “User Name.”
  • Code – “UserName.”
  • Data type – select “Text (250 characters).”
  • Value – click Process parameter and select the “User Name” process element.

Click Save.

To add a business process parameter that will contain the password for the email sender’s mailbox, execute the Add parametersText action in the Parameters tab of the setup area and specify the following parameter properties:

  • Title – “Password.”
  • Code – “Password.”
  • Data type – select “Text (250 characters).”
  • Value – click Process parameter and select the “Password” process element.

Click Save.

To add a business process parameter that will contain the email recipient’s mailbox, execute the Add parametersText action in the Parameters tab of the setup area and specify the following parameter properties:

  • Title – “Recipient.”
  • Code – “Recipient.”
  • Value – click Process parameter and select the “Recipient (many recipients separated by semicolon ";")” process element.

Click Save.

To add a business process parameter that will contain the type of the email sender’s mail provider, execute the Add parametersOtherUnique identifier action in the Parameters tab of the setup area and specify the following parameter properties:

  • Title – "Type of mail server".
  • Code – “ServerTypeId.”
  • Value – click Process parameter and select the “Type of mail server” process element.

Click Save.

To add a business process parameter that will contain the email sender’s mailbox, execute the Add parametersText action in the Parameters tab of the setup area and specify the following parameter properties:

  • Title – "Sender Mailbox".
  • Code – “SenderMailbox.”
  • Data type – select “Text (250 characters).”
  • Value – click Process parameter and select the “Sender Mailbox” process element.

Click Save.

7. Add methods

To add business process methods, click in the Usings block in the Methods tab of the process designer setup area, and specify Terrasoft.Mail.Sender value in the Name Space field. Click Save.

Using the same method, add the following namespaces:

  • Terrasoft.Core.Factories
  • System.Linq

Save all changes in the Process Designer.

8. Business process launch

After the business process is run using the Run button, a page containing fields for specifying email parameters will open.

To send an email using the explicit account credentials, click Continue.


Resources

Package with example implementation