Download Attachments from email server.

Status
Not open for further replies.

tdromgoo

Beta member
Messages
5
Can anyone tell me how I could download an attachment from a remote email server?

I have a user name and password to an account that I need to check every night at 12am to see if a specific email has shown up.


I need to do this without Outlook automation

Thanks,
Thomas.
 
tdromgoo said:
Can anyone tell me how I could download an attachment from a remote email server?

I have a user name and password to an account that I need to check every night at 12am to see if a specific email has shown up.


I need to do this without Outlook automation

Thanks,
Thomas.
lol im lame but i just wanted to see that u name pwnz :)
 
Yes I need to do this with CDO code or some code that I can programmatically get access to a email account with visual basic 6 or .net
 
You can create a CDO session and login with the UID and PW:

Dim objSession As MAPI.Session
On Error GoTo err_CreateSessionAndLogon

Set objSession = CreateObject("MAPI.Session")
' call objSession.SetLocaleIDs here if you need to change your locale
objSession.Logon "myProfile", "myPassword", True, True
Util_CreateSessionAndLogon = True

err_CreateSessionAndLogon:
if err then
If (Err = 1275) Then ' VB4.0: If Err.Number = CdoE_USER_CANCEL Then
MsgBox "User pressed Cancel"
Else
MsgBox "Unrecoverable Error:" & Err
End If
Util_CreateSessionAndLogon = False
end if

if Util_CreateSessionAndLogon = then
set oInBOx = objSession.GetDefaultFolder (olFolderInbox)

'Now add logic to find the msg
 
Hey Jack,

I couldn't get your could to work but I did get the following code to work.

**************************************************
Dim oSession As MAPI.Session
Dim oMessage As MAPI.Message
Dim oMessages As MAPI.Messages
Dim oInbox As MAPI.Folder
Dim oAttachment As MAPI.Attachment
Dim oAttachments As MAPI.Attachments

Private Sub Form_Load()
Set oSession = CreateObject("MAPI.Session")
strProfileInfo = "server" & vbLf & "user"
oSession.Logon NewSession:=True, NoMail:=False, showDialog:=False, ProfileInfo:=strProfileInfo
Set oInbox = oSession.Inbox
Set oMessages = oInbox.Messages

Dim objItem As Object
Dim dteCreateDate As Date
Dim strSubject As String
Dim strItemType As String
Dim strBody As String
Dim intCounter As Integer

For A = 1 To oMessages.Count
Set oMessage = oMessages.Item(A)
With oMessage
If LCase(.Subject) = "subject" Then
Set oAttachments = oMessage.Attachments
dteCreateDate = .TimeCreated
strSubject = .Subject
strItemType = TypeName(oMessage)

PathString = "D:\My Documents\Email Reader\"

For I = 1 To oAttachments.Count
Set oAttachment = oAttachments.Item(I)
PathString = PathString & oAttachment.Name
oAttachment.WriteToFile PathString
Next

Debug.Print vbTab & "Item #" & intCounter & " - " _
& strItemType & " - created on " _
& Format(dteCreateDate, "mmmm dd, yyyy hh:mm am/pm") _
& vbCrLf & vbTab & vbTab & "Subject: '" _
& strSubject & "'" & vbCrLf _
& strBody & vbCrLf
End If
End With
Next
End Sub

Private Sub Form_Terminate()
On Error Resume Next
If Not (oSession Is Nothing) Then
oSession.Logoff
Set oSession = Nothing
End If
End Sub
 
Are you kidding ?
Hey Jack,

I couldn't get your could to work but I did get the following code to work.

**************************************************

Dim oSession As MAPI.Session
Dim oMessage As MAPI.Message
Dim oMessages As MAPI.Messages
Dim oInbox As MAPI.Folder
Dim oAttachment As MAPI.Attachment
Dim oAttachments As MAPI.Attachments

Private Sub Form_Load()
Set oSession = CreateObject("MAPI.Session")
strProfileInfo = "server" & vbLf & "user"
oSession.Logon NewSession:=True, NoMail:=False, showDialog:=False, ProfileInfo:=strProfileInfo
Set oInbox = oSession.Inbox
Set oMessages = oInbox.Messages

Dim objItem As Object
Dim dteCreateDate As Date
Dim strSubject As String
Dim strItemType As String
Dim strBody As String
Dim intCounter As Integer

For A = 1 To oMessages.Count
Set oMessage = oMessages.Item(A)
With oMessage
If LCase(.Subject) = "subject" Then
Set oAttachments = oMessage.Attachments
dteCreateDate = .TimeCreated
strSubject = .Subject
strItemType = TypeName(oMessage)

PathString = "D:\My Documents\Email Reader\"

For I = 1 To oAttachments.Count
Set oAttachment = oAttachments.Item(I)
PathString = PathString & oAttachment.Name
oAttachment.WriteToFile PathString
Next

Debug.Print vbTab & "Item #" & intCounter & " - " _
& strItemType & " - created on " _
& Format(dteCreateDate, "mmmm dd, yyyy hh:mm am/pm") _
& vbCrLf & vbTab & vbTab & "Subject: '" _
& strSubject & "'" & vbCrLf _
& strBody & vbCrLf
End If
End With
Next
End Sub

Private Sub Form_Terminate()
On Error Resume Next
If Not (oSession Is Nothing) Then
oSession.Logoff
Set oSession = Nothing
End If
End Sub
====
Email servers do not cripple you this way.
Lets start over.Try Yahoo.com
 
Status
Not open for further replies.
Back
Top Bottom