Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Diagnostics;
- using System.Linq;
- using System.ServiceProcess;
- using System.Text;
- using System.Threading.Tasks;
- using System.Threading;
- using System.IO.Ports;
- using System.Xml;
- using System.Net;
- namespace GmailNotifyDaemon
- {
- public partial class Service1 : ServiceBase
- {
- public Service1()
- {
- InitializeComponent();
- }
- protected override void OnStart(string[] args)
- {
- int unread;
- try
- {
- SerialPort port = new SerialPort("COM3", 9600, Parity.None, 8, StopBits.One);
- port.Open();
- //string tostop = "0";
- unread = checkmail();
- while (true)
- {
- unread = checkmail();
- //Console.WriteLine("Unread Mails: " + unread.ToString());
- port.Write(unread.ToString());
- Thread.Sleep(5000);
- //Console.WriteLine(port.ReadLine());
- }
- }
- catch (Exception er)
- {
- //Console.WriteLine("Error on Connection to COM4: " + er);
- }
- }
- static int checkmail()
- {
- int nr = 0;
- try
- {
- System.Net.WebClient objClient = new System.Net.WebClient();
- string response;
- // string title;
- //string summary;
- //Creating a new xml document
- XmlDocument doc = new XmlDocument();
- //Logging in Gmail server to get data
- objClient.Credentials = new System.Net.NetworkCredential("litruv@gmail.com", "imD1ff3r3n+");
- //reading data and converting to string
- response = Encoding.UTF8.GetString(objClient.DownloadData(@"https://mail.google.com/mail/feed/atom"));
- response = response.Replace(@"<feed version=""0.3"" xmlns=""http://purl.org/atom/ns#"">", @"<feed>");
- //loading into an XML so we can get information easily
- doc.LoadXml(response);
- //nr of emails
- nr = Int32.Parse(doc.SelectSingleNode(@"/feed/fullcount").InnerText);
- // Console.WriteLine(nr);
- }
- catch (Exception e)
- {
- //Console.WriteLine("Check your network connection. ERROR: " + e);
- }
- return nr;
- }
- protected override void OnStop()
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement