我们在这里用的是一个dll控件,此控件的功能很强大,大家可以到http://www.hi-ho.ne.jp/babaq/eng/basp21.html下载并安装这个控件,下面我来讲一下具体的实现方法和代码
首先,我自己写了一个dll,调用下载的那个dll,提供了几个接口,可以填入发送人和接受人等等信息,此控件代码如下:
Imports BASP21Lib
Imports System.IO
Imports System.io.Directory
Public Shared Sub send(ByVal sendadd As String, ByVal resvAdd As String, ByVal subject As String, ByVal content As String)
Dim basptest As New BASP21Lib.Basp21
basptest.SendMail("192.168.1.19", sendadd, resvAdd, subject, content, "")
End Sub
Public Shared Sub checkmail(ByVal tesadd As String, ByVal password As String)
Dim basptest As New BASP21Lib.Basp21
Dim test As String
Dim resvAdd As String
Dim arrFile As Object
Dim eachF As Object
Dim strMailInfo As String
Dim strLast As Object
Dim thePath As String
Dim mes As Object
Dim message As String
thePath = GetCurrentDirectory() & CStr("\Mail")
strMailInfo = "from:to:X-to:Cc:X-Cc:Bcc:subject:Date:MIME-Version: " & "Content-Type:X-Priority:X-MSMail-Priority:X-Mailer:X-MimeOLE:"
arrFile = basptest.RcvMail("192.168.1.19", tesadd, password, "SAVEALLD", thePath)
If IsArray(arrFile) = False Then
Exit Sub
End If
For Each eachF In arrFile
strLast = basptest.ReadMail(eachF, strMailInfo, thePath)
For Each mes In strLast
message = message & mes & vbCrLf
Next mes
Next eachF
basptest.SendMail("192.168.1.19", "xxx@iddddia.com", "xxx@ixxx.net.cn", "ddddd", "ddddddddddddd", "")
End Sub
End Class
然后我们利用系统服务来调用这个dll,代码如下:
Protected Overrides Sub OnStart(ByVal args() As String)
' サービスを開始するためのコードをここに追加します。このメソッドで、設定を行いながら
' サービスの実行が妨げられないようにします。
Dim timer1 As New Timer
timer1.Interval = 1000
timer1.Enabled = True
End Sub
Protected Overrides Sub OnStop()
' サービスを停止するのに必要な終了処理を実行するコードをここに追加します。
End Sub
Private Sub Timer1_Elapsed(ByVal sender As System.Object, ByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
newmail.newmailclass.checkmail("ss@eee.net.cn", "werwer")
End Sub
End Class
通过调用dll里的收邮件和发邮件函数自动实现邮件的转发,做成系统服务,调用这个dll,设置为自动启动,以后你的机器就多了一个功能(提供给有需要的用户)