ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] ºÊ±±¥Ø¿ý²§°Êlog & VB¶l¥óµ{¦¡

[µo°Ý] ºÊ±±¥Ø¿ý²§°Êlog & VB¶l¥óµ{¦¡

Dear ¤j¤j­Ì¡A

¤p§Ì³Ìªñ¦b¼g¤@¥\¯àªºVB¡C
¨ä¥\¯à¬O¯à°÷ºÊ±±1¸ê®Æ§¨©M¤l¥Ø¿ýªºÀɮײ§°Ê(·s¼W¡B§R°£¡B­×§ï)ªº®É¶¡log°O¿ý¡C
¨Ã¥B¨C¦³²§°Ê¡A´N¥ÎMailµo¥X³qª¾¡C
Mail §tlogªþ¥óÀɮסA©Î±Nlogªº¤º®e¶K¤W¶l¥ó¤º¤å¡C

¦ý¤p§Ì¤~­è¾Ç¤£¤[¡A¹ï©ó°j°éif ³o¨ÇÆ[©À«Ü³¡·|...¡C
¥H¤U¨â­Óµ{¦¡¦pªG³æ¿W°õ¦æ³£¨S¦³°ÝÃD¡C
1­Ó¬Omailªºclass¡A1­Ó¬OºÊ±±¥Ø¿ýªºclass¡C
·Q½Ð±Ð¤j¤j¦pªG¨â­Óµ{¦¡ªº¥\¯àµ²¦X¤@°_¡C
À³¸Ó­n«ç»ò­×§ï©O?

ÁÂÁ¦U¦ì¤j¤j~
  1. Public Class Mail001


  2.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  3.         Dim To_Address As String = "[email protected]"

  4.         ' ³]©wSMTPserver
  5.         Dim SMTP_Server As New Net.Mail.SmtpClient("google.smtp.com")
  6.         Dim Mailmsg As New System.Net.Mail.MailMessage
  7.         Dim MailBodyHtml As String

  8.         ' ³]©w¤@­Ó«H¥óªºªþÀÉ
  9.         Dim mail_attachment As New System.Net.Mail.Attachment("C:\VB_Mail.rar")

  10.         Mailmsg.IsBodyHtml = True ' ¬°html¤º®e®æ¦¡

  11.         ' ¦¹«Hªº±H¥ó¤H
  12.         Mailmsg.From = New Net.Mail.MailAddress("[email protected]", "webb")
  13.         Mailmsg.Subject = "test_webb"
  14.         MailBodyHtml = "Mail Message First"
  15.         MailBodyHtml &= "Mail Message Second"
  16.         Mailmsg.Body = MailBodyHtml

  17.         ' §âªþÀÉ¥[¤J¨ìMail
  18.         Mailmsg.Attachments.Add(mail_attachment)

  19.         ' ±N¦r¦ê¸Ìªº;¤À¬°¦h­Ó¦¬¥ó¤H
  20.         For Each MA As String In To_Address.Split(";")
  21.             Mailmsg.To.Add(New Net.Mail.MailAddress(MA, "[email protected]"))
  22.         Next

  23.         ' ±K¥ó°Æ¥»¦¬¥ó¤H
  24.         ' Mailmsg.Bcc.Add(New Net.Mail.MailAddress("[email protected]"))
  25.         ' Mailmsg.Priority = Net.Mail.MailPriority.Normal

  26.         ' Smtp(Server) ªº±b¸¹»P±K½X
  27.         SMTP_Server.Credentials = New System.Net.NetworkCredential("Liuxxx", "123456")
  28.         SMTP_Server.Send(Mailmsg)
  29.         MessageBox.Show("Message sent.")
½Æ»s¥N½X
  1. ¥ý±q¤u¨ã½c´¡¤J¥H¤Uª«¥ó
  2. txt_watchpath           '      TextBox  (for folder path)
  3. btn_startwatch          '      Button   (start watching)
  4. btn_stop                '      Button   (stop watching)
  5. txt_folderactivity      '      Textbox  (folder activity)


  6. Imports System.IO
  7. Imports System.Diagnostics


  8. Public Class webb_000
  9.     Public watchfolder As FileSystemWatcher


  10.     Private Sub btn_startwatch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_startwatch.Click

  11.         watchfolder = New System.IO.FileSystemWatcher()

  12.         'this is the path we want to monitor

  13.         watchfolder.Path = txt_watchpath.Text

  14.         'Add a list of Filter we want to specify

  15.         'make sure you use OR for each Filter as we need to

  16.         'all of those
  17.         watchfolder.IncludeSubdirectories = True 'ºÊµø¤l¥Ø¿ý
  18.         watchfolder.NotifyFilter = IO.NotifyFilters.DirectoryName
  19.         watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
  20.                                    IO.NotifyFilters.FileName
  21.         watchfolder.NotifyFilter = watchfolder.NotifyFilter Or _
  22.                                    IO.NotifyFilters.Attributes
  23.         ' add the handler to each event
  24.         AddHandler watchfolder.Changed, AddressOf logchange
  25.         AddHandler watchfolder.Created, AddressOf logchange
  26.         AddHandler watchfolder.Deleted, AddressOf logchange

  27.         ' add the rename handler as the signature is different

  28.         AddHandler watchfolder.Renamed, AddressOf logrename

  29.         'Set this property to true to start watching
  30.         watchfolder.EnableRaisingEvents = True

  31.         btn_startwatch.Enabled = False
  32.         btn_stop.Enabled = True

  33.         'End of code for btn_start_click
  34.     End Sub

  35.     Private Sub txt_folderactivity_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_folderactivity.TextChanged
  36.     End Sub
  37.     Private Sub logchange(ByVal source As Object, ByVal e As  _
  38.                      System.IO.FileSystemEventArgs)
  39.         If e.ChangeType = IO.WatcherChangeTypes.Changed Then
  40.             txt_folderactivity.Text &= "File " & e.FullPath & _
  41.                                     "¤w­×§ï" & Now & vbCrLf
  42.         End If
  43.         If e.ChangeType = IO.WatcherChangeTypes.Created Then
  44.             txt_folderactivity.Text &= "File " & e.FullPath & _
  45.                                      " has been created¤w«Ø¥ß" & Now & vbCrLf
  46.         End If
  47.         If e.ChangeType = IO.WatcherChangeTypes.Deleted Then
  48.             txt_folderactivity.Text &= "File " & e.FullPath & _
  49.                                     " ¤w§R°£" & Now & vbCrLf    'Now ´N¬O¥Ø«e¤é´Á®É¶¡
  50.         End If
  51.     End Sub


  52.     Public Sub logrename(ByVal source As Object, ByVal e As  _
  53.                                 System.IO.RenamedEventArgs)
  54.         txt_folderactivity.Text &= "File" & e.OldName & _
  55.                       " has been renamed to ¤w§ó¦W¬°" & e.Name & vbCrLf
  56.     End Sub
  57.     Private Sub btn_stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_stop.Click
  58.         ' Stop watching the folder

  59.         watchfolder.EnableRaisingEvents = False
  60.         btn_startwatch.Enabled = True
  61.         btn_stop.Enabled = False
  62.     End Sub
  63. End Class
½Æ»s¥N½X

        ÀR«ä¦Û¦b : ¤£­nÀH¤ß©Ò±ý¡A­nÀH¤ß±Ð¨|¦Û¤v¡C
ªð¦^¦Cªí ¤W¤@¥DÃD