#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    40
    Rep Power
    11

    Question Saving Exchange Server attachments


    Hi I have a python script that i need to run every time an e-mail is received from a certain person. I want to check if an e-mail has been received, save the attachment and then run my script. Can anyone point me in the right direction for connecting to Microsoft exhange server and saving attachments

    thanks
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    155
    Packet log the Microsoft Exchange Server while in progress, gather enough information, create code with the use of sockets accordingly to connect to the server and send/recv what you require.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    40
    Rep Power
    11

    saving e-mail attachments


    i know how to connect to the server and count the number of messages and get the details of a certain message if its place in the list is known. I dont know how to check for attachments on the mail and save it into a folder. can anyone let me know how i can loop through the list and look search for attachments and save the attachments.


    Code:
    import poplib
    a = poplib.POP3('host')
    a.user('username')
    a.pass_('password')
    (numMsgs, totalSize) = a.stat()
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    40
    Rep Power
    11
    if the attachment is a text file i can search for the filename and add all lines and create a new text file as below. However, does anybody know how i can save the attachment if it is a zip file for example


    Code:
    for thisNum in range(1, numMsgs + 1):
    	response, lines, bytes = pop.retr(thisNum)
    	FileLines = []
    	true = 0
    	for x in lines:
    		if '''filename="file.txt"''' in x:
    			true = 1
    		if true == 1:
    				FileLines.append(x)
    	        if true == 1:
    		        output = open('path\\filename.txt', 'a')
    		for x in FileLines:
    			output.writelines(x + '\n')
    		output.close()

IMN logo majestic logo threadwatch logo seochat tools logo