Get mailBoxSize with Invoke Code

I need to develop a process that tells me the capacity I have left in a mailbox.

I have this code that I would like to run with UiPath using Invoke code activity and VB.Net:

Imports Spire.Email.Pop3

Namespace Get_mailbox_information
Class Program
Private Shared Sub Main(args As String())
'Create a pop3 client
Using pop As New Pop3Client()
'Set host, authentication, port and connection protocol
pop.Host = “outlook.office365.com
pop.Username = “LeonDavisLD@outlook.com
pop.Password = “password”
pop.Port = 995
pop.EnableSsl = True

			'Connect the pop server
			pop.Connect()

			'Get the number of messages
			Console.WriteLine("Mailbox message count: " + pop.GetMessageCount())

			'Get the size of mailbox
			Console.WriteLine("Mailbox size: " + pop.GetSize() + " bytes")

			'Get the unique id of the first message
			Console.WriteLine("Message uid: " + pop.GetMessagesUid(1))
		End Using
	End Sub
End Class

End Namespace

The output arguments would be out_mailBoxSize, which would return the bytes of capacity that the mailbox has.

Can anyone help me?

@Marisa_Ontiveros1

You can try this as below:

Imports Spire.Email.Pop3

’ Initialize the mailbox size variable
out_mailBoxSize = 0

Try
’ Create a POP3 client
Using pop As New Pop3Client()
’ Set host, authentication, port, and connection protocol
pop.Host = “outlook.office365.com
pop.Username = “LeonDavisLD@outlook.com
pop.Password = “your_password_here” ’ Replace with secure method
pop.Port = 995
pop.EnableSsl = True

    ' Connect to the POP server
    pop.Connect()

    ' Get the size of the mailbox
    out_mailBoxSize = pop.GetSize() ' Assign the size to the output argument

    ' Optionally, you can also get the number of messages if needed
    ' Console.WriteLine("Mailbox message count: " + pop.GetMessageCount())
    ' Console.WriteLine("Mailbox size: " + out_mailBoxSize + " bytes")
End Using

Catch ex As Exception
’ Handle exceptions, log error messages
Console.WriteLine("Error: " + ex.Message)
End Try

I get errors in this code when I copy and paste this code in the Invoke Code editor.

For example, in the first line Imports Spire.Email.Pop3, in Imports, I get the following error:

Module member declaration expected.

’ Create a POP3 client
Dim pop As New Spire.Email.Pop3.Pop3Client()
’ Set host, authentication, port, and connection protocol
pop.Host = “outlook.office365.com
pop.Username = username
pop.Password = password
pop.Port = 995
pop.EnableSsl = True

’ Connect to the POP server
pop.Connect()

’ Get the size of the mailbox
out_mailBoxSize = pop.GetSize()

@Marisa_Ontiveros1

first you need to install the spire package form manage packages if available else you need to find a nupkg and install it that is when you can invoke it using invoke code and make it run

Also clauses like import or using and class are not supported in invoke code it is to plainly write a code and run it

cheers

It has been very helpful to me, thank you.

1 Like