You are not logged in.
Hello guys,
I'm looking for a script that outputs the number of new mails I received from my Mail Account with Google Apps.
I've already found a script that works pretty well with the normal Gmail but not obviously not with Google Apps.
import os
import string
#Enter your username and password below within double quotes
# eg. username="username" and password="password"
username="username"
password="********"
com="wget -O - https://"+username+":"+password+"@mail.google.com/mail/feed/atom --no-check-certificate"
temp=os.popen(com)
msg=temp.read()
index=string.find(msg,"<fullcount>")
index2=string.find(msg,"</fullcount>")
fc=int(msg[index+11:index2])
if fc==0:
print "0 new"
else:
print str(fc)+" new"
My idea was to replace mail.google.com/mail/feed/atom with mail.google.com/a/domain.tld/feed/atom but I always get connection errors like this.
Connection to mail.google.com|209.85.135.16|:443... connected.
HTTP request sent, wait for answer... 401 Unauthorized
Connection to mail.google.com|209.85.135.16|:443... connected.
HTTP request sent, wait for answer... 401 Unauthorized
Authorisation failed.
Traceback (most recent call last):
File "/home/orschiro/.scripts/mail.py", line 15, in <module>
fc=int(msg[index+11:index2])
ValueError: invalid literal for int() with base 10: ''
Any suggestion what I could try?
Thank you in advance.
Last edited by orschiro (2009-06-19 17:55:07)
Offline
Here's a script I wrote that you might try. Not used it with google apps.
#!/usr/bin/perl
use strict;
use warnings;
use XML::Atom::Client;
my $api = XML::Atom::Client->new;
$api->username('username');
$api->password('password');
my $feed = $api->getFeed('https://mail.google.com/mail/feed/atom')
or die ("Error: ", $api->errstr, "\n");
print(scalar($feed->entries)||0, "\n");
Offline
Here is part of a script that I am using with my Google Apps domain. Should be easy to follow. Just edit the three variables at the top of the script. I prompt for the password at boot so it is not hard coded in the script. I use x11-ssh-askpass for this.
MAIL_URL = ['https://', 'mail.google.com', '/a/domain.com/feed/atom']
USERNAME = "user@domain.com"
PASSWD = "password"
def initMail():
passman = urllib2.HTTPPasswordMgrWithDefaultRealm()
passman.add_password(None, MAIL_URL[1], USERNAME, PASSWD)
authhandler = urllib2.HTTPBasicAuthHandler(passman)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
def checkMail():
logging.debug("checkMail()")
try:
f = urllib2.urlopen("".join(MAIL_URL))
doc = xml.dom.minidom.parseString(f.read())
c = doc.getElementsByTagName("fullcount")[0].firstChild.data
return dzenH1("Mail: ") + c
except urllib2.URLError as e:
return dzenH1("Mail: ") + "URLError"
Offline