Click here to Skip to main content
Click here to Skip to main content

Custom GMail Vacation Auto-Responder

By , 27 May 2009
 
Prize winner in Competition "Best VB.NET article of May 2009"

Introduction

I'm a Systems Engineer who works in an Anonymous Company. My indirect supervisor (my boss's boss) wanted to have a custom GMail Vacation Auto-Responder that would:

  1. Have a list of involved GMail accounts.
  2. Connect to GMail and identify unread messages.
  3. Auto-Reply to the senders of those unread messages with a custom auto-reply template.

Well, this could have been done easily using the GMail Atom Feed (https://mail.google.com/mail/feed/atom/), but since the atom only provides access to the very latest 20 unread messages, it could not be used for that purpose.

So, I had only one of two choices, either use POP3 or IMAP. Of course, IMAP was the right candidate for many considerations, the most prudent of which is its resourceful command-set. I had to design the tool (a Windows Service in this case) with minimal data transfer/session time in mind, because Google becomes touchy when you over-use IMAP with its servers.

I was new to the whole Socket/IMAP thing, so I had to get my feet wet. I designed the tool, planned it well, and thought the best work-flow would go like this:

  1. Loop into an account collection.
  2. For each account:
    • open connection
    • connect to GMail
    • get list of unread messages *since* a pre-set start-date
    • get headers of those messages
    • parse those headers and extract (Message-ID, From)
    • record unique From headers, based on Message-ID header, for non-duplicity
    • set unread messages that have been processed as "read"
    • close connection with GMail
  3. Start auto-responding with the auto-reply template for all collected senders.

Well, my boss's boss had some comments - that he never really declared which makes them IMPLICIT :D :D :D - on the way the tool works, but he decided to spell the word only when I announced that my proto-type code is done. He is not supposed to be technically involved - I mean into code - although he really involves himself into bits and bytes, and he has not even seen the code, not to mention that he might not fully understand it, but yet somehow he declared that what I did was a waste of time.

Hence, being a time-waster I decided that I might make it a habit of my own and waste your own time as well :D :D :D by posting the code of that little tool. So, please enjoy wasting your time with my code :D :D :D.

Project Code and Usage Notes

Please download the final project code and usage notes from http://admincraft.net.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

About the Author

_Khallaf

Egypt Egypt
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionImap plain text loginmemberkaandemirtas25-Oct-10 9:27 
Dear Khallaf,
 
I think this is a very good article. Especially about imap. There are very few articles like this and I think this is the best one. I converted your code to csharp but stuck at login. My servers don't accept ssl login. So, I cannot use the code. I would be very happy if you can show us the way to use the code with plain text login.
 
Thanks and regards,
 
Kaan
AnswerRe: Imap plain text loginmember_Khallaf27-Oct-10 8:43 
Hi Kaan,
 
Greetings to all of Turkey and thank you for your interest in this article.
 
The trickier part is actually SSL login, not Plain Text. I mean, if I wanted Plain Text login I could have completed the code much easier. I had to search for quite some time to know how it was possible to DirectCast an SslStream over a generic System.IO.Stream, so that I could use the .AuthenticateAsClient() method.
 
I suppose all you would need is to make these lines:
 
conStream = New SslStream(connector.GetStream(), False)
conStream.ReadTimeout = -1<br/>
DirectCast(conStream, SslStream).AuthenticateAsClient(serverName)
readConStream = New StreamReader(conStream, Encoding.ASCII, True)
 
look like this....
 
conStream = connector.GetStream()
conStream.ReadTimeout = -1<br/>
readConStream = New StreamReader(conStream, Encoding.ASCII, True)
 

Try that and tell me how it goes Smile | :)
 
BR,
 
Khallaf
GeneralMy vote of 1memberMember 294974326-Jan-10 14:44 
All download links point to essentially empty projects with no useful code.
GeneralRe: My vote of 1member_Khallaf27-Jan-10 8:09 
Gimap.Responder.zip > Config.zip > Service.Code.Final.txt.
 
also read: Gimap.Responder.zip > Config.zip > notes.txt
 

 

"If the killer was enough patient, the victim would have died by himself!"
 
An Egyptian wisdom Smile | :)
GeneralCongratulationsmemberAbhishek Sur22-Jun-09 22:06 
Congrats, you have dont it. Rose | [Rose] Rose | [Rose]
 

GeneralRe: Congratulationsmember_Khallaf22-Jun-09 23:20 
Abhishek Sur wrote:
Congrats, you have dont it. RoseRose

 
Dear Abhishek Sur,
 
Thanks to you Smile | :)
 
BR,
Khallaf
GeneralIf you like it, please vote for this article as Best VB.Net article.member_Khallaf12-Jun-09 10:05 
Vote here please http://www.codeproject.com/script/Surveys/VoteForm.aspx?srvid=926[^]
GeneralFixes and updatesmember_Khallaf10-Jun-09 8:19 
There has been some important fixes to the code. Get it at http://admincraft.net (opens in new window)
GeneralFinal Updatemember_Khallaf27-May-09 23:35 
Final update to the code has been reflected here on the downloadable source, and you can also download it from my website http://admincraft.net[^]
GeneralBetter Code Highlighting + Updates to the Article (if any)member_Khallaf22-May-09 23:39 
You will find a better, excellent highlighted code and future code updates to this article (if any) on this link....
 
http://vbcity.com/forums/topic.asp?tid=161430[^]
 

Best Regards,
 
Khallaf

GeneralRe: Better Code Highlighting + Updates to the Article (if any)member_Khallaf23-May-09 2:57 
I've included here simple details/generic examples and usage notes on the code. Get them at the above mentioned address. Hope you find them useful.
 

BR,
 
Khallaf

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web01 | 2.6.130617.1 | Last Updated 27 May 2009
Article Copyright 2009 by _Khallaf
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid