visual basic attachment
Publicado por jorgetf (3 intervenciones) el 20/03/2007 14:10:26
Hola:
He encontrado un codigo para visual basic para acceder a mi cuenta de gmail sin necesidad de utilizar las librerias del outlook, para saber si hay correo en la cuenta, lo que quiero es saber es como descargar los documentos adjuntos que llegan en los correos.
ption Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Dim m_sServer, m_sUser, m_sPass As String
Private m_oPop3 As ANPOPLib.POPMAIN
Private m_oMsg As ANPOPLib.POPMSG
'============================================================================
'Form_Load
'============================================================================
Private Sub Form_Load()
On Error GoTo ErrCreateObject
Set m_oPop3 = New ANPOPLib.POPMAIN
Set m_oMsg = New ANPOPLib.POPMSG
m_oMsg.RegisterKey = "your license code" 'put your license code here
'm_oPop3.SSL_registerkey = "your SSL/TLS license code"
'm_oPop3.LogFileName = "c:\pop3.log" 'enable pop3 session log
txtPath.Text = App.Path & "\temp"
Exit Sub
ErrCreateObject:
MsgBox "create anpop pop3 component instance failed, " _
& "please make sure this component " _
& "has been propertly installed on your machine"
End Sub
'============================================================================
' btnCheck_Click
'============================================================================
Private Sub btnCheck_Click()
Dim nRet, nCount, i, nSize As Long
Dim errStr, messageId As String
errStr = ""
btnCheck.Enabled = False
If txtServer.Text = "" Or txtUser.Text = "" Or txtPass.Text = "" Then
errStr = "Please input POP3 server address, username and password!"
GoTo ErrCheckEmails
End If
m_oPop3.SSL_uninit
Dim nSSLPort, nPort
If chkIMAP4.Value = Checked Then
m_oPop3.IMAP4Connection = 1
nSSLPort = 993
nPort = 143
Else
m_oPop3.IMAP4Connection = 0
nSSLPort = 995
nPort = 110
End If
If chkSSL.Value = Checked Then
m_oPop3.ServerPort = nSSLPort
If m_oPop3.SSL_init() <> 0 Then
MsgBox "Initialize SSL/TLS library failed"
Exit Sub
End If
Else
m_oPop3.ServerPort = nPort
End If
nRet = m_oPop3.Connect(txtServer.Text, _
txtUser.Text, _
txtPass.Text) ' Connecting POP3 server
If nRet <> 0 Then 'Connecting server fails, exit sub.
errStr = "Connecting server fails, " _
& "Please retry later and make sure username and password are correct."
GoTo ErrCheckEmails
End If
m_sServer = txtServer.Text
m_sUser = txtUser.Text
m_sPass = txtPass.Text
nCount = m_oPop3.GetTotalOfMails() 'Getting total count of mails existing on POP3 server
If nCount = -1 Then
errStr = "Error with GetTotalOfMails method"
GoTo ErrCheckEmails
End If
lsvMails.ListItems.Clear
For i = 1 To nCount
messageId = m_oPop3.GetMsgID(i) 'Getting unique identifier of message.
If messageId = vbNullString Then
errStr = "Error with GetMsgID method"
GoTo ErrCheckEmails
End If
nSize = m_oPop3.GetMsgSize(i) 'Getting message's size
If nSize = -1 Then
errStr = "Error with GetMsgSize method"
GoTo ErrCheckEmails
End If
Call lsvMails.ListItems.Add(i, , messageId)
Call lsvMails.ListItems(i).ListSubItems.Add(, , CStr(nSize))
Next
MsgBox "Total " & nCount & " mail(s)!"
ErrCheckEmails:
Call m_oPop3.Close
If Trim(errStr) <> "" Then
Call MsgBox(errStr)
End If
btnCheck.Enabled = True
End Sub
He encontrado un codigo para visual basic para acceder a mi cuenta de gmail sin necesidad de utilizar las librerias del outlook, para saber si hay correo en la cuenta, lo que quiero es saber es como descargar los documentos adjuntos que llegan en los correos.
ption Explicit
Private Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" (ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) As Long
Dim m_sServer, m_sUser, m_sPass As String
Private m_oPop3 As ANPOPLib.POPMAIN
Private m_oMsg As ANPOPLib.POPMSG
'============================================================================
'Form_Load
'============================================================================
Private Sub Form_Load()
On Error GoTo ErrCreateObject
Set m_oPop3 = New ANPOPLib.POPMAIN
Set m_oMsg = New ANPOPLib.POPMSG
m_oMsg.RegisterKey = "your license code" 'put your license code here
'm_oPop3.SSL_registerkey = "your SSL/TLS license code"
'm_oPop3.LogFileName = "c:\pop3.log" 'enable pop3 session log
txtPath.Text = App.Path & "\temp"
Exit Sub
ErrCreateObject:
MsgBox "create anpop pop3 component instance failed, " _
& "please make sure this component " _
& "has been propertly installed on your machine"
End Sub
'============================================================================
' btnCheck_Click
'============================================================================
Private Sub btnCheck_Click()
Dim nRet, nCount, i, nSize As Long
Dim errStr, messageId As String
errStr = ""
btnCheck.Enabled = False
If txtServer.Text = "" Or txtUser.Text = "" Or txtPass.Text = "" Then
errStr = "Please input POP3 server address, username and password!"
GoTo ErrCheckEmails
End If
m_oPop3.SSL_uninit
Dim nSSLPort, nPort
If chkIMAP4.Value = Checked Then
m_oPop3.IMAP4Connection = 1
nSSLPort = 993
nPort = 143
Else
m_oPop3.IMAP4Connection = 0
nSSLPort = 995
nPort = 110
End If
If chkSSL.Value = Checked Then
m_oPop3.ServerPort = nSSLPort
If m_oPop3.SSL_init() <> 0 Then
MsgBox "Initialize SSL/TLS library failed"
Exit Sub
End If
Else
m_oPop3.ServerPort = nPort
End If
nRet = m_oPop3.Connect(txtServer.Text, _
txtUser.Text, _
txtPass.Text) ' Connecting POP3 server
If nRet <> 0 Then 'Connecting server fails, exit sub.
errStr = "Connecting server fails, " _
& "Please retry later and make sure username and password are correct."
GoTo ErrCheckEmails
End If
m_sServer = txtServer.Text
m_sUser = txtUser.Text
m_sPass = txtPass.Text
nCount = m_oPop3.GetTotalOfMails() 'Getting total count of mails existing on POP3 server
If nCount = -1 Then
errStr = "Error with GetTotalOfMails method"
GoTo ErrCheckEmails
End If
lsvMails.ListItems.Clear
For i = 1 To nCount
messageId = m_oPop3.GetMsgID(i) 'Getting unique identifier of message.
If messageId = vbNullString Then
errStr = "Error with GetMsgID method"
GoTo ErrCheckEmails
End If
nSize = m_oPop3.GetMsgSize(i) 'Getting message's size
If nSize = -1 Then
errStr = "Error with GetMsgSize method"
GoTo ErrCheckEmails
End If
Call lsvMails.ListItems.Add(i, , messageId)
Call lsvMails.ListItems(i).ListSubItems.Add(, , CStr(nSize))
Next
MsgBox "Total " & nCount & " mail(s)!"
ErrCheckEmails:
Call m_oPop3.Close
If Trim(errStr) <> "" Then
Call MsgBox(errStr)
End If
btnCheck.Enabled = True
End Sub
Valora esta pregunta


0