Any video tutorial regarding email automation using OpenRPA?

Hi Peeps,

Greetings!

Is there any video Tutorial regarding email automation using OpenRPA?

Many thanks and cheers,

OpenRPA

@willowdan
I didn’t find a video on this topic, but I have experience reading an email using RPA

You can use the “Get Mail” activity, but in my opinion it is not very convenient, since it only takes emails through Outlook, which is running on the machine on which the process is running. I always use the “Email” block in Node-RED, with which you can connect to the mail server address using one of the mail protocols (you need to download the node-red-node-email extension). Next, you need to obtain the necessary data from the letter object (subject, sender, some link from the body, etc.) and generate a message with parameters that will already go to OpenRPA.
In my opinion this is a pretty convenient way

3 Likes

Hello @Velinkton,

Greetings!

Surely I’ll give that a try, as I plan to explore Node-RED soon.

Many thanks and cheers,
dante

use this vb.net code to read mail from gmail you can just need to replace variables value according to your configuration.
Try
’ Create a folder named “inbox” under current directory
’ to save the email retrieved.

        Dim localInbox As String = String.Format("{0}\inbox", Directory.GetCurrentDirectory())

        ' If the folder is not existed, create it.
        If Not Directory.Exists(localInbox) Then
            Directory.CreateDirectory(localInbox)
        End If

        ' Create app password in Google account
        ' https://support.google.com/accounts/answer/185833?hl=en
        ' Gmail IMAP server is "imap.gmail.com"localInbox
        Dim oServer As New MailServer("imap.gmail.com",ArgEmail, ArgPassword,ServerProtocol.Imap4)

        ' Enable SSL/TLS connection, most modern email server require SSL/TLS connection by default.
        oServer.SSLConnection = True
        ' Set 993 IMAP SSL Port
        oServer.Port = 993
        Console.WriteLine("Connecting server ...")

        Dim oClient As New MailClient("TryIt")
        oClient.Connect(oServer)
  Console.Write(ArgSearchFilter)
        Dim MailInfolist As MailInfo() = oClient.SearchMail(ArgSearchFilter)
        Console.WriteLine("Total {0} email(s)", MailInfolist.Length)

        For i As Integer = 0 To MailInfolist.Length - 1
            Dim info As MailInfo = MailInfolist(i)
            Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}", info.Index, info.Size, info.UIDL)

            ' Retrieve email from IMAP server
            Dim oMail As Mail = oClient.GetMail(info)
            ArgMails.Add(oMail)
            Console.WriteLine("From: {0}", oMail.From.ToString())
            Console.WriteLine("Subject: {0}" & vbCr & vbLf, oMail.Subject)
            Console.WriteLine("Body: {0}" & vbCr & vbLf, oMail.TextBody)
            

           


        Next

        ' Quit and expunge emails marked as deleted from IMAP server.
        oClient.Quit()
        Console.WriteLine("Completed!")

Catch ep As Exception
Console.WriteLine(ep.Message)
End Try

3 Likes

Hi @willowdan

If you want to test the OpenRPA “Get Mail” activity here is a small demo for you to test (if you need explanation, let me know): GetMailOutlook.json (16.9 KB)
I really like @Velinkton ideia to use Node-RED “Email”, it’s fantastic tool (imagination is the limit :sweat_smile:).
You can use python or vb.net too like @yashshah showed here.

import imaplib
import email
from email.header import decode_header

# Email account settings
username = "your_email@gmail.com"
password = "your_password"
imap_server = "imap.gmail.com"
port = 993  # Specify the custom port here

# Connect to the IMAP server with the custom port
mail = imaplib.IMAP4_SSL(imap_server, port)
mail.login(username, password)

# Select the mailbox you want to read emails from (e.g., "inbox")
mailbox = "inbox"
mail.select(mailbox)

# Search for emails based on criteria (e.g., UNSEEN for unread emails)
status, email_ids = mail.search(None, "UNSEEN")

# Convert the list of email IDs into a list of individual email IDs
email_id_list = email_ids[0].split()

# Loop through the email IDs and fetch the email content
for email_id in email_id_list:
    # Fetch the email by ID
    status, msg_data = mail.fetch(email_id, "(RFC822)")

    # Parse the email content
    email_message = email.message_from_bytes(msg_data[0][1])
    subject, encoding = decode_header(email_message["Subject"])[0]
    if encoding:
        subject = subject.decode(encoding)
    else:
        subject = str(subject)

    # Print email details
    print("Subject:", subject.encode("utf-8", "ignore").decode("utf-8", "ignore"))
    print("From:", email_message["From"])
    print("Date:", email_message["Date"])

    # If you want to extract the email body, you can do so like this:
    for part in email_message.walk():
        if part.get_content_type() == "text/plain":
            body = part.get_payload(decode=True).decode("utf-8")
            print("Body:")
            print(body)

# Close the mailbox and log out
mail.close()
mail.logout()

Hope this help!

3 Likes

Hi @yashshah ,

Does this solution have to be in the “invoke code” activity?

Cheers,
Dante

Hi @kowts ,

Does your code have to be in the “invoke code” activity?

Cheers,
Dante

Yes . You just have to add invoke code activity in your sequence then select the language to python . Then use this code.

1 Like

@willowdan

Exactly like @Vivek_Sharma explain.

FYI…someone recently implemented a new feature called “ScriptActivities” in openrpa where you can implement this script or any other as a “component” (no need to duplicate the code).
You can find official documentation on github and references here in this forum.

You can run this python script in NodeRed too but you can choose what’s best for your process.

Hope this help!

3 Likes

Hello,

Greetings!

I just tried this as a python script … and it failed, as can be seen in the image below:

Hope I can get help from you peeps.

Many thanks and cheers,
willowdan

Hi @yashshah ,

Greetings!

A road block for me in the app password, seemingly I cannot create one for my Google account …

Many thanks,
willowdan

You can use your google login password in that case

1 Like

Please make sure you enable less secure apps and disable 2 steps authentication in your google account.

1 Like

Hi @yashshah ,

Sorry to disturb you, here’s the new error:

[15:26:47.627][Output] read email failed at 1.5 in 00:01.264

C:\Users\willo\AppData\Local\Temp\kbj45b13.0.vb(32,0) : error BC30002: Type ‘MailServer’ is not defined.C:\Users\willo\AppData\Local\Temp\kbj45b13.0.vb(40,0) : error BC30002: Type ‘MailClient’ is not defined.C:\Users\willo\AppData\Local\Temp\kbj45b13.0.vb(42,0) : error BC32017: Comma, ‘)’, or a valid expression continuation expected.C:\Users\willo\AppData\Local\Temp\kbj45b13.0.vb(43,0) : error BC30002: Type ‘MailInfo’ is not defined.C:\Users\willo\AppData\Local\Temp\kbj45b13.0.vb(47,0) : error BC30002: Type ‘MailInfo’ is not defined.C:\Users\willo\AppData\Local\Temp\kbj45b13.0.vb(51,0) : error BC30002: Type ‘Mail’ is not defined.C:\Users\willo\AppData\Local\Temp\kbj45b13.0.vb(52,0) : error BC30451: ‘ArgMails’ is not declared. It may be inaccessible due to its protection level.

Many thanks in advance,
willowdan

So in order to use password authentication for gmail you need to go to your account, security settings and enable app authentication/legacy signin ( something like that )
But i vaguely remember reading somewhere google was going to deprace that, and force everyone to use alternatives. Im not sure if that has happended yet.

If that is the case, you need to move to nodered or an agent. In nodered i have made a “reques” node that supports all 3 authentication methods for google cloud/suit. Or you could write the code in python/nodejs/csharp and then use credentials or oauth authentication from there.

1 Like

IMPSGetMail.json (11.8 KB)
Try this code

1 Like

Hi @Allan_Zimmermann ,

Greetings!

Will try the Node-Red route later .

Many thanks and cheers,
Willowdan

Hi @yashshah ,

How is that json used, in invoke code activity?

Many thanks and cheers,
Willowdan

I just looked inside it, it’s a openrpa workflow, so you can import it, after selecting a project inside the first tab.

1 Like

Hi @yashshah and @Allan_Zimmermann ,

I encountered this error when I imported the json file:

Many thanks in advance,
Willowdan