IMAP Biblios
This commit is contained in:
@@ -3,6 +3,7 @@ Imports Independentsoft.Email.Imap
|
||||
Imports Independentsoft.Email.Mime
|
||||
Imports DigitalData.EMLProfiler.ClassCurrent
|
||||
Imports DigitalData.Modules.Logging
|
||||
Imports AE
|
||||
Public Class clsEmailIMAP
|
||||
Private Shared Logger As DigitalData.Modules.Logging.Logger
|
||||
|
||||
@@ -16,12 +17,13 @@ Public Class clsEmailIMAP
|
||||
Try
|
||||
Logger.Info(String.Format("Working on IMAP_COLLECT....."))
|
||||
Logger.Debug(String.Format("Working on IMAP_COLLECT....."))
|
||||
Dim oClient As New ImapClient(MAIL_SERVER, MAIL_PORT)
|
||||
Dim oClient As New Independentsoft.Email.Imap.ImapClient(MAIL_SERVER, MAIL_PORT)
|
||||
|
||||
oClient.ValidateRemoteCertificate = False
|
||||
oClient.Connect()
|
||||
oClient.Login(MAIL_USER, MAIL_USER_PW)
|
||||
oClient.SelectFolder("Inbox")
|
||||
Dim oEnvelopes As Envelope() = oClient.ListMessages()
|
||||
Dim oEnvelopes As Independentsoft.Email.Imap.Envelope() = oClient.ListMessages()
|
||||
Dim oCount As Integer = 0
|
||||
For i As Integer = 0 To oEnvelopes.Length - 1
|
||||
If Not IsNothing(oEnvelopes(i).Subject) Then
|
||||
@@ -36,7 +38,7 @@ Public Class clsEmailIMAP
|
||||
End If
|
||||
Next
|
||||
oClient.Disconnect()
|
||||
Logger.Debug($"{oCOUNT.ToString} messages will be worked..")
|
||||
Logger.Debug($"{oCount.ToString} messages will be worked..")
|
||||
Logger.Debug("IMAP_COLLECT finished!")
|
||||
Return True
|
||||
Catch ex As Exception
|
||||
@@ -47,24 +49,29 @@ Public Class clsEmailIMAP
|
||||
Public Function TEST_IMAP_COLLECT(INBOXNAME As String, MYMAIL_SERVER As String, MYMAIL_PORT As Integer, MYMAIL_USER As String, MYMAIL_USER_PW As String)
|
||||
Try
|
||||
Logger.Info(String.Format("Working on TEST_IMAP_COLLECT....."))
|
||||
Dim oLogPath = System.IO.Path.Combine(My.Application.Info.DirectoryPath, "Log\logindependentSoft.txt")
|
||||
Logger.Debug($"IsoftLog: {oLogPath}...")
|
||||
Dim oindependentLogger As New Independentsoft.Email.Logger(oLogPath)
|
||||
|
||||
Dim oImapClient As New ImapClient(MYMAIL_SERVER, MYMAIL_PORT)
|
||||
' oImapClient.ValidateRemoteCertificate = False
|
||||
Dim oImapClient As New Independentsoft.Email.Imap.ImapClient(MYMAIL_SERVER, MYMAIL_PORT)
|
||||
oImapClient.Logger = oindependentLogger
|
||||
oImapClient.ValidateRemoteCertificate = False
|
||||
oImapClient.Connect()
|
||||
Logger.Debug($"oImapClient connected...")
|
||||
Try
|
||||
oImapClient.Login(MAIL_USER, MAIL_USER_PW)
|
||||
oImapClient.Login(MAIL_USER, MAIL_USER_PW, AuthenticationType.Login)
|
||||
Catch ex As Exception
|
||||
MsgBox($"Unexpected error in TEST_IMAP_COLLECT (oImapClient.Login): {ex.Message}")
|
||||
Logger.Info($"Unexpected error in TEST_IMAP_COLLECT - User: [{MYMAIL_USER}] PW: [{MYMAIL_USER_PW}]")
|
||||
MsgBox($"Unexpected error in (oImapClient.Login): {ex.Message}")
|
||||
Logger.Info($"Unexpected error in oImapClient.Login - User: [{MYMAIL_USER}] PW: [{MYMAIL_USER_PW}]")
|
||||
Logger.Warn(ex.StackTrace.ToString)
|
||||
Logger.Warn(ex.Message)
|
||||
|
||||
oImapClient.Logger.Close()
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
|
||||
oImapClient.SelectFolder(INBOXNAME)
|
||||
Dim oEnvelopes As Envelope() = oImapClient.ListMessages()
|
||||
Dim oEnvelopes As Independentsoft.Email.Imap.Envelope() = oImapClient.ListMessages()
|
||||
|
||||
For i As Integer = 0 To oEnvelopes.Length - 1
|
||||
If Not IsNothing(oEnvelopes(i).Subject) Then
|
||||
@@ -75,12 +82,54 @@ Public Class clsEmailIMAP
|
||||
Next
|
||||
|
||||
oImapClient.Disconnect()
|
||||
oImapClient.Logger.Close()
|
||||
Logger.Info("TEST_IMAP_COLLECT finished!")
|
||||
Return True
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Info($"Unexpected error in TEST_IMAP_COLLECT - User: [{MYMAIL_USER}] PW: [{MYMAIL_USER_PW}]")
|
||||
MsgBox($"Unexpected error in TEST_IMAP_COLLECT: {ex.Message}")
|
||||
Logger.Error(ex, "Unexpected Error in TEST_IMAP_COLLECT:")
|
||||
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
Public Function TEST_AEIMAP_COLLECT(INBOXNAME As String, MYMAIL_SERVER As String, MYMAIL_PORT As Integer, MYMAIL_USER As String, MYMAIL_USER_PW As String)
|
||||
Try
|
||||
Logger.Info(String.Format("Working on TEST_AEIMAP_COLLECT....."))
|
||||
'Dim oLogPath = System.IO.Path.Combine(My.Application.Info.DirectoryPath, "Log\logindependentSoft.txt")
|
||||
'Logger.Debug($"IsoftLog: {oLogPath}...")
|
||||
'Dim oindependentLogger As New Independentsoft.Email.Logger(oLogPath)
|
||||
' Dim sslProtocol As System.Security.Authentication.SslProtocols = Security.Authentication.SslProtocols.Default
|
||||
Dim oImapClient As New AE.Net.Mail.ImapClient(MYMAIL_SERVER, MYMAIL_USER, MYMAIL_USER_PW, AE.Net.Mail.AuthMethods.Login, MYMAIL_PORT)
|
||||
'oImapClient.Logger = oindependentLogger
|
||||
'oImapClient.ValidateRemoteCertificate = False
|
||||
Try
|
||||
If (oImapClient.IsConnected) Then
|
||||
Logger.Debug($"oImapClient Login successfull...")
|
||||
Else
|
||||
Logger.Info($"oImapClient NOT connected...")
|
||||
Return False
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Logger.Warn(ex.Message)
|
||||
Logger.Error(ex)
|
||||
Return False
|
||||
End Try
|
||||
|
||||
|
||||
|
||||
oImapClient.Disconnect()
|
||||
|
||||
|
||||
|
||||
Logger.Info("TEST_IMAP_COLLECT finished!")
|
||||
Return True
|
||||
|
||||
Catch ex As Exception
|
||||
Logger.Info($"Unexpected error in TEST_IMAP_COLLECT - User: [{MYMAIL_USER}] PW: [{MYMAIL_USER_PW}]")
|
||||
Logger.Error(ex, "Unexpected Error in TEST_IMAP_COLLECT:")
|
||||
MsgBox($"Unexpected error in TEST_IMAP_COLLECT: {ex.Message}")
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
Reference in New Issue
Block a user