Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Computer Forums > Programmers Lounge > Programming Discussions » Download Attachments from email server.
Closed Thread
Old 02-03-2004, 04:40 PM   #1 (permalink)
 
Newb Techie

Join Date: Feb 2004

Posts: 5

tdromgoo

Question Download Attachments from email server.

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 is offline  
Old 02-03-2004, 04:53 PM   #2 (permalink)
 
Banned

Join Date: May 2003

Posts: 105

imported_Jack

Default

Without Outlook Automation, do you mean you intend to do this directly with CDO?
imported_Jack is offline  
Old 02-03-2004, 05:02 PM   #3 (permalink)
 
Newb Techie

Join Date: Feb 2004

Posts: 4

Chosy

Default Re: Download Attachments from email server.

Quote:
Originally posted by tdromgoo
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
Chosy is offline  
Old 02-03-2004, 05:06 PM   #4 (permalink)
 
Newb Techie

Join Date: Feb 2004

Posts: 5

tdromgoo

Default

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
tdromgoo is offline  
Old 02-03-2004, 07:13 PM   #5 (permalink)
 
Banned

Join Date: May 2003

Posts: 105

imported_Jack

Default

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
imported_Jack is offline  
Old 02-04-2004, 03:21 PM   #6 (permalink)
 
Newb Techie

Join Date: Feb 2004

Posts: 5

tdromgoo

Default

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
tdromgoo is offline  
Old 02-15-2004, 12:11 AM   #7 (permalink)
 
Banned

Join Date: Feb 2004

Posts: 241

stan-the-man

Default

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
stan-the-man is offline  
 
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On