Skip to main content
Posted On 27 Mar 2023

Automate Send Mail process after Report Generation in Tosca using TCShell

I agree to Privacy Policy

We have discussed in detail, steps to Automate report generation using TCShell in our previous Insights Article- Automate Report Generation in Tosca using TCShell. Now, after generation of report we need to send it to stakeholders via email. In this article we will automate Send report via Email process. To automate the process of sending an email we should focus on below steps:

  1. We should have report generated as a pre-requisite for which refer steps in Blog - Automate Report Generation in Tosca using TCShell
  2. For the creation of Send Mail test case we would need to create 2 test steps. One to connect to Mail server and another to send an email.
  3. Connect to Mail Server test step allows us to specify email server details which we would have to test. Following are attributes of the test step and its functions in brief:
    • Connection Name – A unique name which would act as Object pointer between test step Connect to Mail server and Send Mail. The Tosca Mail engine uses this name to connect to other test steps of Mail engine
    • Mail Server – Domain name of the mail server. Example – gmail, outloo
    • Username – Email address / username of the account which would be used to access mail server
    • Password – Password of the username of the account
    • Port – Port number using which we would connect to mail server. We should check with IT team that the port number is not blocked by the firewall
    • Enable Security – To perform mail operations we should decide if we want to use a secure connection with SSL/TLS certificates. Accordingly, we would choose to give either true or false as a value in this attribute. If value is set to true it would instruct Tosca to look for secure connection and if it is false Tosca will not look for secure connection
    • Protocol – This attribute will hold the value of network protocol we would want to use. The value is:
      1. Simple Mail transfer Protocol (SMTP)
      2. Post Office Protocol (POP3)
      3. Internet Message Access Protocol (IMAP)
  4. Send Mail test step allows us to send an email using any of the three available protocols. Attributes with short description of its usages are as follows
    • Connection Name - A unique name which would act as Object pointer between test step Connect to Mail server and Send Mail. The Tosca Mail engine uses this name to connect to other test steps of Mail engine
    • From-> Address – Sender’s Email Address
    • From-> Name – Sender’s Name
    • Subject – Subject line of the email
    • To – Recipient’s Email Address. To add multiple recipients, use “;”
    • Cc – Optional field, however we can add additional multiple recipients whom we want to copy
    • Bcc – Optional field, however we can add multiple recipients if needs to be blind copied
    • Body – Email content has to be written here
    • Attachment – Optional field, however if we have any attachment to be added we can use this attribute. Use complete path of the file to be attached
    • Reply To-> Mail To Reply – Optional field, however it will need name of the saved email
    • Reply To-> reply Options – Optional field, however based on the Reply Options email will be shared with recipients
      1. Replay – Email will be shared to sender only
      2. ReplyAll – Email is shared to all the recipients / address in the email
  5. In our blog we will use gmail as our mail server and the details for Connect to Server test step will be as mentioned in the table below:

    ConnectionNameEmailConnect
    MailServersmtp.gmail.com
    UsernameSenders Gmail Address
    PasswordSenders Gmail Address Password
    Port587
    EnableSecurityTRUE
    ProtocolSMTP

    Table 1

    In our case we are using Gmail. As we want to use SSL/TLS security our Enable Security value is set to “True”. We would have to create a App password to be used as Password instead of our gmail password.

  6. In order to generate App password for gmail we have to follow below steps:
    • Login to your gmail account
    • Click on the profile and then click on “Manage your Google Account” as in Figure 1

      Figure 1

    • We will be navigated to the Google accounts page. Now, navigate to the Security page by clicking on the Security link from the left as in Figure 2

      Figure 2

    • On Security page scroll down to “How you sign in to Google section” and enable “2-step Verification” as in Figure 3

      Figure 3

    • Click on 2-step Verification and then click on Get Started on 2-step Verification page
    • Enter your mobile number and then complete the mobile number set up using One time password received on your mobile
    • Now click on Turn on link to complete the 2-step Verification set up as in Figure 4

      Figure 4

    • 2-Step Verification is completed as shown in Figure 5

      Figure 5

    • Now, we will generate App password and to do the same please scroll up and type “app passwords” in the search bar as shown in Figure 6

      Figure 6

    • Click on the link highlighted in Figure 6 and enter values for Select app and Select device from the dropdowns. Refer Figures 7, 8 & 9 for the values entered

      Figure 7

      Figure 8

      Figure 9

    • Now click on Generate button and app password will be generated as in Figure 10. App password length is of 16 characters copy it and enter in Password field of Connect to Main server test step

      Figure 10

    • App password generated will look like as in Figure 11

      Figure 11

  7. We have all the details to enter on Connect to Mail server test step. Please enter the details as per Table 1. Refer Figure 12 for reference.

    Figure 12

    To allows us to have dynamic values for Connect to Mail server we can store them in buffer variables from TDS or Test Configuration parameters and then use in our test steps as shown in Figure 12

  8. In Send Mail test step, enter all the values as per Table 2 and then create a test step in Tosca as per Figure 13

    ConnectionNameEmailConnect
    From-> AddressSenders Gmail Address
    From-> NameName of the Sender
    SubjectTest Execution Report
    ToRecipients Gmail Address
    MailContentPlease find attached execution report
    AttachmentFull Path of the attachment along with file name

    Table 2

    Figure 13

    To allows us to have dynamic values for Send email we can store them in buffer variables from TDS or Test Configuration parameters and then use in our test steps as shown in Figure 13

  9. Drag and drop this test case to different Execution list which would be invoked by .bat file created in Blog - Automate Report Generation in Tosca using TCShell, which in tun will execute the execution list which has send mail test case.
  10. The process we followed for Mail server – gmail is the same process for Mail server – outlook. Details we have used in test step, Connect to Mail server to automate Send Mail via Outlook is updated in Table 3
    ConnectionNameOutlookConnect
    MailServersmtp.office365.com
    UsernameSenders Gmail Address
    PasswordSenders Gmail Address Password
    Port587
    EnableSecurityTrue
    ProtocolSMTP

    Table 3

  11. We need to get App password which we will enter in Password field to enable 2-Step verification for us to allow to send email via outlook. We have to follow this process as Microsoft uses modern authentication techniques and has deprecated the basic authentication method.

    Following steps will help you create App password for personal account setup.

    • If we have setup personal outlook account, then navigate to Security page from your account page. Refer Figure 14

      Figure 14

    • Click on Turn on Two-step verification from the security page in Figure 14 and scroll down to Additional security section and click on Turn on Two-step verification as in Figure 15

      Figure 15

    • Follow the set-up steps Click on Next as in Figure 16

      Figure 16

    • Save the generated code and click on Next as in Figure 17

      Figure 17

    • Click on Next if we do not wish to sync any of the listed devices as in Figure 18

      Figure 18

    • Click on Finish to complete the set-up of 2-Step verification and navigate to Security page and scroll down till App passwords section to create app password as in Figure 19, 20

      Figure 19

      Figure 20

    • Click on Create new app password and generated password will be shown as in figure 21. Save the password and click on done button

      Figure 21

    • Now we can use the password to Connect to Mail server

  12. Generation of App password for Office accounts

    • Navigate to your Microsoft account using below link and then Navigate to Security Info page as shown in Figure 22
      My Account (microsoft.com)

      Figure 22

    • Click on Add Sign In method “Add a method window” will open and select App Password as highlighted in Figure 23

      Figure 23

    • Click on Add button

      Figure 24

    • Enter a Name and then click on Next as shown in Figure 25

      Figure 25

    • App password is generated, save it and click on Done as shown in Figure 26

      Figure 26

    • App password is added as shown in Figure 27. Now use this password for further steps and automate the Send email process

      Figure 27

  13. Details for Send Mail test step would be as Table 4

    ConnectionNameOutlookConnect
    From-> AddressSenders Gmail Address
    From-> NameName of the Sender
    SubjectTest Execution Report
    ToRecipients Gmail Address
    MailContentPlease find attached execution report
    AttachmentFull Path of the attachment along with file name

    Table 4

  14. To allows us to have dynamic values for Connect to Mail Server and Send email test steps we can store them in buffer variables from TDS or Test Configuration parameters and then use in our test steps as shown in Figure 28

    Figure 28

  15. Drag and drop this test case to different Execution list which would be invoked by .bat file created in Blog - Automate Report Generation in Tosca using TCShell, which in turn will execute the execution list which has send mail test case.

Category