Getting Unread Gmail as an Atom Feed in VB.NET
Gmail currently provides a list of unread emails in a subscriber's inbox as an Atom feed. While that may change in the future, the following Alintex Script code will retrieve and print the returned XML given a username and password.
Update: see also |this post| which shows how to display the xml as html in your browser, and also provides a C# version of gmail.vb
Run the script as follows:
ax[w]script [username] [password] gmail.vb
Paste the following into a file named gmail.vb and run it as shown in the line above.
' gmail.vb - gets unread gmail as an atom feed
' for Alintex Script - www.alintex.com
' usage: ax(w)script [username] [password] gmail.vbimports System
imports System.Net
imports System.IO
imports System.Text#region "Script"
' check commandline arguments
if (args.Length < 2)
print("gmail.vb - gets unread gmail as an atom feed")
print("Usage: ax(w)script [username] [password] gmail.vb")
return
end if' connect to gmail and retrieve the atom xml feed
client = new WebClient
bytes = Encoding.ASCII.GetBytes(args(0) & ":" & args(1))
client.Headers.Add("Authorization", "Basic " & _
Convert.ToBase64String(bytes))gmailUri = "https://gmail.google.com/gmail/feed/atom"
dim feedStream as Stream = client.OpenRead(gmailUri)
reader = new StreamReader(feedStream)
feedAsXml = reader.ReadToEnd()
feedStream.Close()
print(feedAsXml)#end region
Note:
- the code above doesn't need to handle exceptions as the script shell does it for you by default.
- the password is not transmitted in plaintext.
- if your username includes a '.' character, Alintex Script will think your specifying a file on the commandline. In that case use the /a[rgument] switch instead i.e. /a:my.name,password.