First of all, let me briefly explain how an Email works?
We know we can login any email ID and send any email we want, but what happens at the back-end?!
Think about, how mail processing work in post office?
Step 1: You are in Chennai and you write a mail to your friend in Bangalore
Step 2: You go to post office and post the mail. (Your job over here)
Step 3: People working in Chennai post office identify the recipient address and the respective post office. Then they send the mail to Bangalore post office.
Step 4: Bangalore post office receives the mail.
Step 5: Post man helps in carrying the mail to the recipient address. The job ends here and your friend receives the mail 😊
Scenario: You need to send an email from your personal Gmail ID to your friend who use Yahoo ID
Let me relate the email processing with mail processing
Step 1: You logged in your Gmail ID – firstname.lastname@example.org and sent an email to your recipient address.
Step 2: The mail reaches the SMTP email server. Here I don’t use any proxy network, so by default It reach the Gmail email server.
Note: Email servers helps in relaying the email message to recipient
Step 3: SMTP Email server uses DNS to identify the Email server of the recipient email address email@example.com Yeah its Yahoo 😊. It sends the mail to recipient email server
Step 4: The recipient Email server receives the Email and they can use IMAP or POP3 protocol.
Step 5: Finally the recipient – firstname.lastname@example.org receives the email using any one of the above protocol
- SMTP – protocol used for sending email
- IMAP/POP3 – protocol used for receiving email
In this post, we are going to send an outbound email.
What are the things required for you to create an outbound email account?
- You need to have an valid email address from a valid email providers (google, yahoo etc)
- You need to know the SMTP email server details
- SMTP server host name
- SMTP server port number
What is an Email account?
- Email account is a data instance
- It belongs to Integration resources category.
- Email account instance holds the account details both for outbound (outgoing) and inbound (incoming) emails.
How do you configure an Email account instance?
Pega provides a simple wizard to configure an Email account.
Step 1: Designer studio -> Integration -> Email -> Email Wizard
Step 2: Wizard starts. Enter Email Information.
What would you like to do? –
a) Receive an email and create a workobject – Use it for email service, when we need to process the incoming emails
b) Configure an email account – To create an email account and use it for outbound emails
Here we select – Configure an email account
Would you like to use the Default EmailAccount Key?
If you check this option, you can make this email account as default account – Means a common account.
Why do we need a default account?
- Every email account can be tagged to a work pool. Actually, the email account data instance name will be the same as the work pool name it is tagged to.
- But it is not mandatory for every work pool to have an email account.
Say for example, I create a sales case in ‘OIKGGB-MyKnowPega-Work’ Workpool. I need to send the correspondence to the customer. But I didn’t tag any email account to sales case workpool.
Now think Pega handles this? Before sending an outbound email from a case, Pega checks If there is any email account tagged with the case work pool.
- If Yes, then Pega sends the mail from the email account.
- If No, then Pega sends the mail from Default email account.
Default Email account can act as a base (common) email account in a Pega application.
So, when you want to create a Default email account check the checkbox.
You can see the work pool selection disappears 😊
Which work pool will be associated with this email account – you can select the workpool from the dropdown.
- You can see a note message there.
- It means, if there is already an email account tagged to a workpool, then this wizard just updates the email account and don’t create a new one 😊
In this tutorial, we will create a new email account for the workpool ‘OIKGGB-MyKnowPega-Work’
Click on next screen.
Step 3: In the wizard 2nd step, enter the account details.
Enter Account Info
Select email provider – provided with a link. You can click on and select an email provider.
These are the email providers, Pega support.
- Here I am going to select – Google Gmail
- As soon as you select the email provider and submit, the connection details are pre-populated in the sender and receiver blocks.
First let’s fill the Identity info
Full name – Enter the full name of the Sender
From – Enter the mail ID, from which you will be send the email
User ID – If there is some email ID the SMTP host use, then specify the ID there, else you can copy the same from ‘From’ field we used above
Password – Click on the link & enter the email Id password.
Reply To – You can enter a valid email address, so that recipients of the outbound email can reply.
- This is where you configure the details about SMTP email server
Host (SMTP) – provide the host name of SMTP email server.
What are the things to note down, when configuring SMTP Host?
- Here I use personal edition & connected directly with internet. I don’t have any proxy connection between. So, I use the Gmail SMTP host ‘smtp.gmail.com’
- If you are connected in any Organization proxy network, then you need to specify the SMTP host of the organization email server not the Gmail SMTP host
Inside proxy network, If you provide the Gmail host and test the connectivity, you will get the below error
If you see this type of error, then please check with administrators and get the Organization Email server host name 😊 (this may occur, If the Gmail SMTP server down too. This is very rare 😉)
Port – Enter the SMTP server port number.
Note: To make any connection to any server, you need an open port connection.
There are three available SMTP ports
a) 25 – This is the default port used for transmitting mails between servers. Introduced very long back, before I came into this world.
b) 587 – This is the recommended port to be used for SMTP communication. It uses STARTTLS connection.
c) 465 – This port was introduced to support SSL means of sending email messages. But the same can be done by 587.
What port to choose 25 or 587 or 465?
- 25 – This is still used by many email servers around the world. This is mainly used when we need to relay the emails between different email servers. The main drawback is this can be exploited to spread spam & malware
Note: If you use Organization email server(proxy network), then you need to get both the host name and port number from the administrator
- 587 – This is highly recommended port and use STARTTLS connection. STARTTLS can initiate a TLS/SSL connection and secure the messages. Approved by authorities.
- 465 – This was introduced to support SMTPS connection, secured way to transmit messages but not lived up to the expectation. Still some email servers open up the 465 port for SMTPS connection. There were some fear that this port can be brought down.
Note: My advice (If no proxy network) go with 587 port to connect email servers
Use SMPTS? –
- You can select this option to secure the email message.
- When selected, you need to use port number – 465
As I mentioned before, this is not recommended. Port 587 can secure the message.
I am going to use port 587
Message signing –
Why do we need message signing?
- The email servers help in relaying emails. If they don’t use secure connection, then there is a possibility that the email can be read by hackers.
- To encrypt the email.
How do we do it?
Step 1: You need to get the help from companies that offer digital certificates (.jks or .pfx )
Digital certificates – they are the public and private keys which can be shared only with the recipient to decrypt the email
Step 2: Create a keystore instance and upload the .jks file
Step 3: Include the keystore instance in the message signing section email account.
- Now your message is digitally signed.
Note: You need to share the key with the recipient to decrypt the email.
Though we are going to configure mail ID only for outbound, we need to fill out the receiver section too for inbound email to avoid wizard validation.
User ID – Same as sender fill the email ID to receive the incoming emails
Password – Input the password for the User ID you use above.
- Here we can use two protocols – IMAP, POP3 protocol
Note : At this point, the email is available in the receiver email server. Now the receiver mail client ( mail ID) needs to access the mail from the server.
What is the difference between IMAP & POP3 protocol?
Say you have synced your mail ID s in both mobile and laptop.
- When you access the Gmail to check the mails from laptop, the mail gets downloaded in the laptop and gets deleted from the email server. So when you try syncing from mobile, you will not find the mail.
- It use 110 (unsecured) , 995 (secured) port numbers
- When you access the Gmail to check the mails from laptop, the mail still resides in the mail server and will not be deleted.
- It use 143 (unsecured) , 993 (secured) port numbers
Always try to use IMAP protocol to receive the email.
Host Name – you can specify the receiver emailing server hostname
For gmail – imap.gmail.com / pop3.gmail.com
Note: As we saw before in sender section, If the client receives the mail inside proxy network organization, you need to get the hostname port number from the administrator.
Port – Always try to use secured ports
IMAP – 993; POP3 – 995
Use SSL/TLS – You can use SSL/TLS connection to receive the email
- There may be situation to modify some properties in receiving servers. You can add those parameters here.
For example, when you use Microsoft exchange servers to receive the incoming email, you need to disable plain authentication
Key – mail.imaps.auth.plain.disable; Value – true
Note: Consult with administrators and complete it with care 😊
- Huh! Let’s move to next screen. Click next on the wizard
Step 4: You can review the details in this screen.
- After reviewing click on next
Step 5: You can see the email account created in the confirmation screen.
- Click on done to close the wizard.
Let’s open the Email account instance.
- You can see all the details completed from the wizard.
- Use the test connectivity button at the top to test the connection.
- We get an authentication problem.
- This is because in Gmail application, they don’t allow less secure apps to access them.
- In my case I use personal edition and it is a less secure app.
How to enable Gmail to allow less secure apps?
Step 1: login the email Id, you provided in the sender information.
Step 2: Click on your profile pic in top right corner and open My account.
Step 3: Click on Sign-in & security.
Enable Allow less secure apps ON.
Step 4: Test the connectivity button again.
- You can also test by checking SMTPS connection in port 465.
- This is because Gmail servers open up both the ports to receive the incoming email.
Now the mail account is ready to send any mail to anyone from Pega 😃
It’s time to test what we developed.
What are the pre-requisites to test an email account?
a) Create correspondence rule
I created a simple correspondence rule – Greetings.
b) Create a simple flow rule in the workpool class – ‘OIKGGB-MyKnowPega-Work’
How to test the outbound email?
Step 1: Open the flow rule and add a Send Email shape from smart shapes palette.
Step 2: Double click on the Send email shape and configure the properties.
Step 3: Save & run the flow.
You can see the mail successfully attached with the case.
Step 4: Login the mail ID & verify.
Things to remember
- Have a valid email ID & password
- If you are connecting from proxy organization network, then get the Email server host name & port to connect.
- For SMTP protocol, prefer 587 port number (STARTTLS) over 465 port number (SMTPS)
- For receiving mail prefer IMAP over POP3
Email Integration is very simple to configure.
You can follow the above steps in the post and try sending email from Pega 😊
Have fun !!!