473,651 Members | 2,533 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

using poplib to retrieve messages sent from a certain address

Real quick, I have account X and I want a python script that goes in
and looks for emails sent from Y and then to save them. i'm trying to
go off the swen killer I have listed below (which i took from someone
on this NG):

import poplib
import time

print 'Start at', time.asctime()

host = 'X'
port = 110
user = 'username'
pasw = 'password'

logfilename = 'sent_from_mobi le_phone'
minsize = 130000
maxsize = 180000
fromtag = 'From user@domain %s\n'

ps = poplib.POP3(hos t, port)
ps.user(user)
ps.pass_(pasw)

messages = ps.list()
print '%d messages, %d bytes' % (len(messages[1]), messages[-1])

logfile = open(logfilenam e, 'a')

for sms in messages[1]:
sid, ssize = sms.split()
if minsize <= int(ssize) < maxsize:
message = ps.retr(sid)
print 'retrieving and deleting msg#%s, %d bytes, %d lines' % (
sid, message[-1], len(message[1]))
logfile.write(f romtag % time.asctime())
for line in message[1]:
logfile.write(l ine)
logfile.write(" \n")
logfile.write(' \n')
ps.dele(sid)

ps.quit()

print 'Done at', time.asctime()
print
Jul 18 '05 #1
1 3021
Rybread wrote:
Real quick, I have account X and I want a python script that goes in
and looks for emails sent from Y and then to save them. i'm trying to
go off the swen killer I have listed below (which i took from someone
on this NG):
I was the "someone", and to retrieve the headers (and the first little
bit of a message) you could use 'top' method of Pop3 objects. However,
the docs warn you:

"""
top(which, howmuch)
Retrieves the message header plus howmuch lines of the message after the
header of message number which. Result is in form (response, ['line', ...],
octets).

The POP3 TOP command this method uses, unlike the RETR command, doesn't set
the message's seen flag; unfortunately, TOP is poorly specified in the RFCs
and is frequently broken in off-brand servers. Test this method by hand
against the POP3 servers you will use before trusting it.
"""

So, you'd be using that at your own risk. If you KNOW it works well
with your server, then, basically:
for sms in messages[1]:
sid, ssize = sms.split()
if minsize <= int(ssize) < maxsize:
resp, lines, octets = ps.top(sid, 1)

if "From: fo*@bar.com" in lines:
message = ps.retr(sid)
print 'retrieving and deleting msg#%s, %d bytes, %d lines' % (
sid, message[-1], len(message[1]))
logfile.write(f romtag % time.asctime())
for line in message[1]:
logfile.write(l ine)
logfile.write(" \n")
logfile.write(' \n')
ps.dele(sid)

ps.quit()

print 'Done at', time.asctime()
print


or thereabouts (untested). You'll probably want to comment-out the
call to ps.dele until you're very secure that it all works...;-).

BTW, for generic tests of POP I find Garshol's popserve.py quite
useful, see http://www.garshol.priv.no/download/...on/popserve.py
.. I think that, as coded, it doesn't support the TOP command (which
you need above), but it does mention a "more full-featured descendant"
that, for all I know, might.
Alex

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2226
by: Giobibo | last post by:
I use the following code to send e-mails with PHP: if(@mail(....)) { //Send OK } else { //Send Bad } But how can I verify that a message was really sent (in case of "Sent
0
1220
by: Will Price | last post by:
I am having problems using UDPClient.Send() in System.Net.Sockets. Each time I make the call to the function, there is a significant delay from when the code is executed to when the packet actually goes out. I took a look at the traffic and found that each time the UDPClient.Send() call was made, two UDP netbios messages go out on port 137. The device on the other end responds each time with an ICMP. After two attempts, the .Send...
3
1908
by: Pebble | last post by:
Hi folks, I have a WebService that simply acts as a thin wrapper to a .Net dll. Literally almost zero code in the WebService. Parameters passed to the WebService are simply used as parameters to methods on the dll, and all parameters to my web methods are strings. (The strings, just for further info, contain XML).
1
1913
by: ManningFan | last post by:
Ha! Now THIS should truly be the final piece. I've recieved an email, I've sent a reply depending on the subject, but now I also want to prevent certain emails I've sent from being stored in my Sent box. Is there a way to use an If/Then block to determine whether or not to save the sent email? Any help would be appreciated!
4
2070
by: kang jia | last post by:
hi i am doing mailinglist currently. the code in my first page is like this : : <html> <head> <link rel="stylesheet" type="text/css" href="gallery.css" /> <script language="JavaScript"> <!--
0
1594
by: Hollywood | last post by:
Good day dear members of the comp.databases.ms-access newsgroup. I'm using the new Acess 2007 "Collect data by using e-mail messages" functionality but it seems the generated e-mail by Outlook 2007 does not support the html list of fields feature. Instead all the options of my lists are displayed at e-mail bottom. Please is there any solution to this problem ?
4
4756
by: Jean-Claude Neveu | last post by:
Hello, I am writing a Python program to check email using POP3. I've tried the sample code from python.org, and it works great. In other words, the code below successfully prints out my emails. import getpass, poplib, email M = poplib.POP3('mail.blah.com') M.user('username') M.pass_('password')
0
659
by: jase | last post by:
can anyone direct me how to set a system wide hook to access the print structure sent to the os when a print command is fired from any application???
2
3020
by: SteveC | last post by:
Hello, I am trying to use POP3_SSL class of the poplib module to read email from my gmail account. I can connect just fine using the example here http://www.python.org/doc/lib/pop3-example.html import getpass, poplib M = poplib.POP3('localhost') M.user(getpass.getuser())
0
8695
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8576
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7296
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6157
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4143
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4281
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2696
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1906
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1585
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.