- Code: Select all
Private Shared Sub GetEmailText() '(args As String())
'Create an ImapClient instance
Dim imap As New ImapClient()
'https://www.e-iceblue.com/Knowledgebase/Spire.Email.html
'Imports Spire.Email
'Imports Spire.Email.IMap
Try
'Set host, port, authentication and connection protocol
imap.Host = "outlook.office365.com"
imap.Port = 143
imap.Username = "x@y"
imap.Password = "12345"
imap.ConnectionProtocols = ConnectionProtocols.Ssl
'Connect the imap server
imap.Connect()
'Select Inbox folder
imap.[Select]("Inbox")
'Search email messages sent from "From"
Dim messages As ImapMessageCollection = imap.Search("'From' Contains 'xxx'")
MsgBox("Number of messages sent from xxx: " & messages.Count, vbInformation, mCompanyName)
'Search email messages with “Year” string in subject
messages = imap.Search("'Subject' Contains '2021'")
MsgBox("Number of messages with '2021' in subject: " & messages.Count, vbInformation, mCompanyName)
Dim msgs As ImapMessageCollection
msgs = imap.Search("'From' Contains 'xxxx'")
MsgBox(msgs.Count & " 'xxxx' found.", vbInformation, mCompanyName)
msgs = imap.Search("'From' Contains 'yyyy")
MsgBox(msgs.Count & " 'yyyy' found.", vbInformation, mCompanyName)
msgs = imap.Search("'Subject' Contains '2021'")
MsgBox(msgs.Count & " '2021' found.", vbInformation, mCompanyName)
Catch ex As Exception
MsgBox(ex.Message, vbExclamation, mCompanyName)
End Try
End Sub
The message boxes show what looks to be the right numbers, but I can't extract the email body text. What should I put to read the collection of body texts? I tried several examples from various Spire questions and responses but the line crashed with eg. '019 bad the specified message set is invalid'.
Perhaps when I've got the args correct? Any help gratefully received. Thank you.