Rambler's Top100
Главная
Новости
Статьи
Форумы
Книги
Коды
Сообщество
Блоги
О нас
 

Логин

Email:
  Пароль:

Войти
Зарегистрироваться
Забыл пароль

Поиск

 Искать :
 
Вперед

Книги по теме

Искать:
в:
Порядок:

Исходник

Автор:

Anton

 
Название:

Проверка почты на сервере NewMail

Дата: 28 August 2003
Описание: Эта программа отображает в интрее конверт в красной рамке, если у вас есть свежая почта на вашем ящике NewMail (ваш_логин@nm.ru). И с красным перечеркнутым кружком, если непрочитанных сообщений нет. Это с моими иконками. Так как я иконки сюда залить не могу, то их Вам придётся нарисовать самим. 
  Разместить ссылку на этот исходник в форуме вы можете вставив в текст сообщения следующую строку: [CODEPOST ID=48]Проверка почты на сервере NewMail[/CODEPOST]
Оценка: Проголосовало 8 посетителей, средняя оценка 4.38
Оценить:
  1 /*
  2      Проверка почты на NewMail
  3 
  4      Антон А. Бурцев
  5      http://burtsev.nm.ru
  6 */
  7 using System;
  8 using System.Reflection;
  9 using System.Resources;
 10 using System.Net;
 11 using System.Web;
 12 using System.Text;
 13 using System.IO;
 14 using System.Threading;
 15 using System.Drawing;
 16 using System.Collections;
 17 using System.ComponentModel;
 18 using System.Windows.Forms;
 19 using System.Runtime.Serialization;
 20 using System.Runtime.Serialization.Formatters.Binary;
 21 
 22 namespace NewMailReminder
 23 {
 24 	/// <summary>
 25 	/// Summary description for Form1.
 26 	/// </summary>
 27 	public class Form1 : System.Windows.Forms.Form
 28 	{
 29 		public const string mbTitle = "New Mail Reminder";
 30 		Hashtable settings = null;
 31 
 32 		private System.Windows.Forms.NotifyIcon notifyIcon1;
 33 		private System.ComponentModel.IContainer components;
 34 		private System.Threading.Timer tmr;
 35 
 36 		private string login = "";
 37 		private System.Windows.Forms.ContextMenu contextMenu1;
 38 		private System.Windows.Forms.MenuItem menuItem1;
 39 		private System.Windows.Forms.MenuItem menuItem2;
 40 		private string password = "";
 41 		private System.Windows.Forms.MenuItem menuItem3;
 42 
 43 		private int MessageCount = 0;
 44 
 45 		private Icon NewMail = null;
 46 		private System.Windows.Forms.MenuItem menuItem4;
 47 		private System.Windows.Forms.MenuItem menuItem5;
 48 		private System.Windows.Forms.Label label1;
 49 		private Icon NoMail  = null;
 50 
 51 		private string CreateURL()
 52 		{
 53 			return "http://www4.nm.ru/cgi-bin/denlogin.cgi?login="+login+"&client=nm%2Eru&passwd="+password;
 54 		}
 55 
 56 		public Form1():base()
 57 		{
 58 			InitializeComponent();
 59 			tmr = new System.Threading.Timer(new TimerCallback(CheckMail), null, 1000, 60000);
 60 			//tmr = new System.Threading.Timer(new TimerCallback(CheckMail), null, 1000, 5000);
 61 			NewMail = new Icon(this.GetType().Assembly.GetManifestResourceStream("NewMailReminder.newmail.ico"));
 62 			NoMail = new Icon(this.GetType().Assembly.GetManifestResourceStream("NewMailReminder.nomail.ico"));
 63 			notifyIcon1.Icon = NoMail;
 64 		}
 65 
 66 		protected override void OnActivated(EventArgs e)
 67 		{
 68 			base.OnActivated (e);
 69 			Visible = false;
 70 		}
 71 
 72 		private void CheckMail(object state)
 73 		{
 74 			// this means it was paused
 75 			if ( menuItem5.Checked ) return;
 76 
 77 			lock(this)
 78 			{
 79 				try
 80 				{
 81 					NewMailWS ws = new NewMailWS();
 82 					int mc = ws.GetNewMessageCount(login,password);
 83 					//int mc = MessageCount + 1;
 84 					if ( mc > 0 )
 85 						notifyIcon1.Icon = NewMail;
 86 					else
 87 						notifyIcon1.Icon = NoMail;
 88 
 89 					if ( mc > MessageCount )
 90 					{
 91 						if ( menuItem3.Checked )
 92 						{
 93 							if ( MessageBox.Show("New mail in your MewMail mailbox! Would you like open mailbox?",mbTitle, MessageBoxButtons.YesNo,MessageBoxIcon.Question) == DialogResult.Yes)
 94 								OpenMailbox();
 95 						}
 96 					}
 97 
 98 					MessageCount = mc;
 99 				}
100 				catch(Exception ee)
101 				{
102 					notifyIcon1.Icon = NoMail;
103 				}
104 			}
105 		}
106 
107 		private void SaveSettings()
108 		{
109 			lock(this)
110 			{
111 				settings = new Hashtable();
112 				settings["notify"] = menuItem3.Checked;
113 				settings["password"] = password;
114 				settings["login"] = login;
115 
116 				IFormatter formatter = new BinaryFormatter();
117 				Stream stream = new FileStream("settings.bin", FileMode.Create);
118 				formatter.Serialize(stream, settings);
119 				stream.Close();
120 			}
121 		}
122 
123 		private void LoadSettings()
124 		{
125 			lock(this)
126 			{
127 				bool edit = false;
128 				try
129 				{
130 					IFormatter formatter = new BinaryFormatter();
131 					Stream stream = new FileStream("settings.bin", FileMode.Open);
132 					Hashtable settings = (Hashtable)formatter.Deserialize(stream);
133 					stream.Close();
134 
135 					menuItem3.Checked = (bool)settings["notify"];
136 					password = (string)settings["password"];
137 					login = (string)settings["login"];
138 				}
139 				catch(Exception e)
140 				{
141 					edit = true;
142 				}
143 				if ( edit ) EditSettings();
144 			}
145 		}
146 
147 		private void EditSettings()
148 		{
149 			Settings s = new Settings();
150 			s.tPassword.Text = password;
151 			s.tLogin.Text = login;
152 			s.chNotify.Checked = menuItem3.Checked;
153 			if ( s.ShowDialog() == DialogResult.OK )
154 			{
155 				password = s.tPassword.Text;
156 				login = s.tLogin.Text;
157 				menuItem3.Checked = s.chNotify.Checked;
158 				SaveSettings();
159 			}
160 
161 		}
162 
163 
164 		/// <summary>
165 		/// Clean up any resources being used.
166 		/// </summary>
167 		protected override void Dispose( bool disposing )
168 		{
169 			if( disposing )
170 			{
171 				if (components != null) 
172 				{
173 					components.Dispose();
174 				}
175 			}
176 			base.Dispose( disposing );
177 		}
178 
179 		#region Windows Form Designer generated code
180 		/// <summary>
181 		/// Required method for Designer support - do not modify
182 		/// the contents of this method with the code editor.
183 		/// </summary>
184 		private void InitializeComponent()
185 		{
186 			this.components = new System.ComponentModel.Container();
187 			this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
188 			this.contextMenu1 = new System.Windows.Forms.ContextMenu();
189 			this.menuItem1 = new System.Windows.Forms.MenuItem();
190 			this.menuItem2 = new System.Windows.Forms.MenuItem();
191 			this.menuItem3 = new System.Windows.Forms.MenuItem();
192 			this.menuItem4 = new System.Windows.Forms.MenuItem();
193 			this.menuItem5 = new System.Windows.Forms.MenuItem();
194 			this.label1 = new System.Windows.Forms.Label();
195 			this.SuspendLayout();
196 			// 
197 			// notifyIcon1
198 			// 
199 			this.notifyIcon1.ContextMenu = this.contextMenu1;
200 			this.notifyIcon1.Text = "New mail into you MewMail mailbox!";
201 			this.notifyIcon1.Visible = true;
202 			this.notifyIcon1.DoubleClick += new System.EventHandler(this.notifyIcon1_DoubleClick);
203 			// 
204 			// contextMenu1
205 			// 
206 			this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
207 																						 this.menuItem1,
208 																						 this.menuItem2,
209 																						 this.menuItem3,
210 																						 this.menuItem4,
211 																						 this.menuItem5});
212 			// 
213 			// menuItem1
214 			// 
215 			this.menuItem1.Index = 0;
216 			this.menuItem1.Text = "Exit";
217 			this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
218 			// 
219 			// menuItem2
220 			// 
221 			this.menuItem2.Index = 1;
222 			this.menuItem2.Text = "Open Mailbox";
223 			this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
224 			// 
225 			// menuItem3
226 			// 
227 			this.menuItem3.Index = 2;
228 			this.menuItem3.Text = "Notify About New Mail";
229 			this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
230 			// 
231 			// menuItem4
232 			// 
233 			this.menuItem4.Index = 3;
234 			this.menuItem4.Text = "Settings...";
235 			this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
236 			// 
237 			// menuItem5
238 			// 
239 			this.menuItem5.Index = 4;
240 			this.menuItem5.Text = "Pause";
241 			this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
242 			// 
243 			// label1
244 			// 
245 			this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel, ((System.Byte)(204)));
246 			this.label1.ForeColor = System.Drawing.Color.DeepPink;
247 			this.label1.Location = new System.Drawing.Point(8, 8);
248 			this.label1.Name = "label1";
249 			this.label1.Size = new System.Drawing.Size(248, 40);
250 			this.label1.TabIndex = 0;
251 			this.label1.Text = "New Mail Reminder";
252 			// 
253 			// Form1
254 			// 
255 			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
256 			this.ClientSize = new System.Drawing.Size(264, 53);
257 			this.Controls.Add(this.label1);
258 			this.Name = "Form1";
259 			this.Text = "Form1";
260 			this.ResumeLayout(false);
261 
262 		}
263 		#endregion
264 
265 		/// <summary>
266 		/// The main entry point for the application.
267 		/// </summary>
268 		[STAThread]
269 		static void Main(string[] args) 
270 		{
271 			Form1 f = new Form1();
272 			f.LoadSettings();
273 			Application.Run(f);
274 			f.SaveSettings();
275 		}
276 
277 		private void OpenMailbox()
278 		{
279 			Microsoft.VisualBasic.Interaction.Shell("explorer \"" + CreateURL() + "\"", Microsoft.VisualBasic.AppWinStyle.MinimizedNoFocus, true, -1);
280 		}
281 
282 		private void notifyIcon1_DoubleClick(object sender, System.EventArgs e)
283 		{
284 			OpenMailbox();
285 		}
286 		private void menuItem1_Click(object sender, System.EventArgs e)
287 		{
288 			notifyIcon1.Visible = false;
289 			Application.Exit();
290 		}
291 
292 		private void menuItem2_Click(object sender, System.EventArgs e)
293 		{
294 			OpenMailbox();		
295 		}
296 
297 		private void menuItem3_Click(object sender, System.EventArgs e)
298 		{
299 			if (menuItem3.Checked)
300 				menuItem3.Checked = false;
301 			else
302 				menuItem3.Checked = true;
303 		}
304 
305 		private void menuItem4_Click(object sender, System.EventArgs e)
306 		{
307 			EditSettings();
308 		}
309 
310 		private void menuItem5_Click(object sender, System.EventArgs e)
311 		{
312 			if (menuItem5.Checked)
313 				menuItem5.Checked = false;
314 			else
315 				menuItem5.Checked = true;
316 		}
317 	}
318 	/// <summary>
319 	/// Summary description for Settings.
320 	/// </summary>
321 	public class Settings : System.Windows.Forms.Form
322 	{
323 		internal System.Windows.Forms.TextBox tLogin;
324 		internal System.Windows.Forms.TextBox tPassword;
325 		private System.Windows.Forms.Label label1;
326 		private System.Windows.Forms.Label label2;
327 		internal System.Windows.Forms.CheckBox chNotify;
328 		private System.Windows.Forms.Button bOK;
329 		private System.Windows.Forms.Button bCancel;
330 		/// <summary>
331 		/// Required designer variable.
332 		/// </summary>
333 		private System.ComponentModel.Container components = null;
334 
335 		public Settings()
336 		{
337 			//
338 			// Required for Windows Form Designer support
339 			//
340 			InitializeComponent();
341 
342 			//
343 			// TODO: Add any constructor code after InitializeComponent call
344 			//
345 		}
346 
347 		/// <summary>
348 		/// Clean up any resources being used.
349 		/// </summary>
350 		protected override void Dispose( bool disposing )
351 		{
352 			if( disposing )
353 			{
354 				if(components != null)
355 				{
356 					components.Dispose();
357 				}
358 			}
359 			base.Dispose( disposing );
360 		}
361 
362 		#region Windows Form Designer generated code
363 		/// <summary>
364 		/// Required method for Designer support - do not modify
365 		/// the contents of this method with the code editor.
366 		/// </summary>
367 		private void InitializeComponent()
368 		{
369 			this.tLogin = new System.Windows.Forms.TextBox();
370 			this.tPassword = new System.Windows.Forms.TextBox();
371 			this.label1 = new System.Windows.Forms.Label();
372 			this.label2 = new System.Windows.Forms.Label();
373 			this.chNotify = new System.Windows.Forms.CheckBox();
374 			this.bOK = new System.Windows.Forms.Button();
375 			this.bCancel = new System.Windows.Forms.Button();
376 			this.SuspendLayout();
377 			// 
378 			// tLogin
379 			// 
380 			this.tLogin.Location = new System.Drawing.Point(72, 16);
381 			this.tLogin.Name = "tLogin";
382 			this.tLogin.Size = new System.Drawing.Size(272, 20);
383 			this.tLogin.TabIndex = 0;
384 			this.tLogin.Text = "";
385 			// 
386 			// tPassword
387 			// 
388 			this.tPassword.Location = new System.Drawing.Point(72, 48);
389 			this.tPassword.Name = "tPassword";
390 			this.tPassword.Size = new System.Drawing.Size(272, 20);
391 			this.tPassword.TabIndex = 0;
392 			this.tPassword.Text = "";
393 			// 
394 			// label1
395 			// 
396 			this.label1.Location = new System.Drawing.Point(8, 16);
397 			this.label1.Name = "label1";
398 			this.label1.Size = new System.Drawing.Size(56, 16);
399 			this.label1.TabIndex = 1;
400 			this.label1.Text = "Login";
401 			// 
402 			// label2
403 			// 
404 			this.label2.Location = new System.Drawing.Point(8, 48);
405 			this.label2.Name = "label2";
406 			this.label2.Size = new System.Drawing.Size(56, 16);
407 			this.label2.TabIndex = 1;
408 			this.label2.Text = "Password";
409 			// 
410 			// chNotify
411 			// 
412 			this.chNotify.Location = new System.Drawing.Point(72, 88);
413 			this.chNotify.Name = "chNotify";
414 			this.chNotify.Size = new System.Drawing.Size(272, 16);
415 			this.chNotify.TabIndex = 2;
416 			this.chNotify.Text = "Notify about new mail";
417 			// 
418 			// bOK
419 			// 
420 			this.bOK.DialogResult = System.Windows.Forms.DialogResult.OK;
421 			this.bOK.Location = new System.Drawing.Point(72, 144);
422 			this.bOK.Name = "bOK";
423 			this.bOK.Size = new System.Drawing.Size(112, 24);
424 			this.bOK.TabIndex = 3;
425 			this.bOK.Text = "OK";
426 			this.bOK.Click += new System.EventHandler(this.bOK_Click);
427 			// 
428 			// bCancel
429 			// 
430 			this.bCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
431 			this.bCancel.Location = new System.Drawing.Point(232, 144);
432 			this.bCancel.Name = "bCancel";
433 			this.bCancel.Size = new System.Drawing.Size(112, 24);
434 			this.bCancel.TabIndex = 3;
435 			this.bCancel.Text = "Cancel";
436 			// 
437 			// Settings
438 			// 
439 			this.AcceptButton = this.bOK;
440 			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
441 			this.CancelButton = this.bCancel;
442 			this.ClientSize = new System.Drawing.Size(368, 189);
443 			this.Controls.Add(this.bOK);
444 			this.Controls.Add(this.chNotify);
445 			this.Controls.Add(this.label1);
446 			this.Controls.Add(this.tLogin);
447 			this.Controls.Add(this.tPassword);
448 			this.Controls.Add(this.label2);
449 			this.Controls.Add(this.bCancel);
450 			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
451 			this.MaximizeBox = false;
452 			this.MinimizeBox = false;
453 			this.Name = "Settings";
454 			this.ShowInTaskbar = false;
455 			this.Text = "Settings";
456 			this.ResumeLayout(false);
457 
458 		}
459 		#endregion
460 
461 		private void bOK_Click(object sender, System.EventArgs e)
462 		{
463 		
464 		}
465 	}
466 
467 	[System.Diagnostics.DebuggerStepThroughAttribute()]
468 	[System.ComponentModel.DesignerCategoryAttribute("code")]
469 	[System.Web.Services.WebServiceBindingAttribute(Name="NewMailWSSoap", Namespace="http://tempuri.org/")]
470 	public class NewMailWS : System.Web.Services.Protocols.SoapHttpClientProtocol 
471 	{
472     
473 		/// <remarks/>
474 		public NewMailWS() 
475 		{
476 			this.Url = "http://Talk.europe.webmatrixhosting.net/NewMailWS.asmx";
477 		}
478     
479 		/// <remarks/>
480 		[System.Web.Services.Protocols.SoapDocumentMethodAttribute("http://tempuri.org/GetNewMessageCount", RequestNamespace="http://tempuri.org/", ResponseNamespace="http://tempuri.org/", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped)]
481 		public int GetNewMessageCount(string login, string password) 
482 		{
483         
484 			Proxy = WebProxy.GetDefaultProxy();
485 			Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
486 
487 			object[] results = this.Invoke("GetNewMessageCount", new object[] {
488 																				  login,
489 																				  password});
490 			return ((int)(results[0]));
491 		}
492     
493 		/// <remarks/>
494 		public System.IAsyncResult BeginGetNewMessageCount(string login, string password, System.AsyncCallback callback, object asyncState) 
495 		{
496 			return this.BeginInvoke("GetNewMessageCount", new object[] {
497 																		   login,
498 																		   password}, callback, asyncState);
499 		}
500     
501 		/// <remarks/>
502 		public int EndGetNewMessageCount(System.IAsyncResult asyncResult) 
503 		{
504 			object[] results = this.EndInvoke(asyncResult);
505 			return ((int)(results[0]));
506 		}
507 	}
508 }
509 
Вернуться к списку исходников в категории Winforms
 
Наш Киев

Apartments for Rent

Rambler's Top100
Рейтинг@Mail.ru
Идея: Dimon aka Manowar Программирование: Dimon aka Manowar Дизайн: Dan Lebedev
Хостинг от компании Parking.ru
Карта сайта