SMTP协议非常简单实在不想再多费口舌。
下面是我写的一段发送邮件控件的源代码的核心部分,没有优化而且时临时摘出来的有些东东没定义,你把它删掉就行,你看看吧
Private Sub wskSend_DataArrival(ByVal bytesTotal As Long)
On Error Resume Next
wskSend.GetData Response ' Check for incoming response *IMPORTANT*
End SubPrivate Sub wskSend_SendComplete()
IsSendComplete = True
End SubPrivate Sub wskSend_SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long)
IsSendComplete = IsSendComplete
End SubPrivate Sub SendEmailFile(DATA As String, MailServerName As String, Port As String, FromEmailAddress As String, ToEmailAddress() As String)
Dim Temp As String
Dim DateNow As String
Dim First As String
Dim Second As String
Dim Rate As Integer
Dim I As LongwskSend.Close
wskSend.LocalPort = 0
PB.Value = 0
timMov.Interval = 150
sStop = False
If wskSend.State = sckClosed Then
DateNow = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0800"
First = "mail from:" + Chr(32) + FromEmailAddress + vbCrLf
wskSend.Close
wskSend.Protocol = sckTCPProtocol
wskSend.RemoteHost = MailServerName '"192.168.0.101"
wskSend.RemotePort = CInt(Port)
wskSend.Connect
If Not WaitFor("220") Then Exit Sub
PutState "正在连接 SMTP 服务器 ..."
If sStop Then Exit Sub
wskSend.SendData ("HELO worldcomputers.com" + vbCrLf)
If Not WaitFor("250") Then Exit Sub
PutState "已经连接服务器"
If sStop Then Exit Sub
wskSend.SendData (First)
PutState "正在发送信笺内容"
If Not WaitFor("250") Then Exit Sub
If sStop Then Exit Sub
For I = LBound(ToEmailAddress) To UBound(ToEmailAddress)
Second = "rcpt to:" + Chr(32) + ToEmailAddress(I) + vbCrLf
wskSend.SendData (Second)
If Not WaitFor("250") Then Exit Sub
Next I
If sStop Then Exit Sub
wskSend.SendData ("data" + vbCrLf)
If Not WaitFor("354") Then Exit Sub
If sStop Then Exit Sub
Dim s As String
Dim iLen As Long
I = 1
iLen = Len(DATA)
Do While (I <= iLen)
PutState CStr(Rate) & "%", Rate
If sStop Then Exit Sub
wskSend.SendData Mid(DATA, I, 2000)
I = I + 2000
Rate = 100 * (I / iLen)
If WaitForSendComplete = False Then
Exit Sub
End If
Loop
If sStop Then Exit Sub
wskSend.SendData (vbCrLf + "." + vbCrLf)
If Not WaitFor("250") Then Exit Sub
If sStop Then Exit Sub
wskSend.SendData ("quit" + vbCrLf)
PutState "正在与服务器断开连接"
If Not WaitFor("221") Then Exit Sub
wskSend.Close
PutState "发送成功。"
timMov.Interval = 0
PB.Value = 100
wskSend.Close
Else
PutState "发送信件过程中出错。"
End If
End SubPrivate Function WaitFor(ResponseCode As String) As Boolean
Dim start
Dim Tmr
Response = "" ' Sent response code to blank **IMPORTANT**
start = Timer ' Time event so won't get stuck in loop
WaitFor = True
Do While Response = ""
If sStop Then Exit Function
Tmr = Timer - start
DoEvents
' DoEvents
' DoEvents ' Let System keep checking for incoming response **IMPORTANT**
If Tmr > 50 Then ' Time in seconds to wait
MsgBox "服务器相应超时!", vbOKOnly, "蓝鸽-SMTP 1.0b"
WaitFor = False
Exit Function
End If
Loop
' While Left(Response, 3) <> ResponseCode
' DoEvents
' If Tmr > 50 Then
' MsgBox "服务器响应错误!", vbOKOnly
' WaitFor = False
' Exit Function
' End If
' Wend
If Left(Response, 3) <> ResponseCode Then
DoEvents
If sStop Then Exit Function
MsgBox "服务器不接受指令: " & Mid(Response, 4), vbOKOnly, "蓝鸽-SMTP 1.0b"
WaitFor = False
Exit Function
End If
End FunctionPrivate Function WaitForSendComplete() As Boolean
Dim start
Dim Tmr
start = Timer ' Time event so won't get stuck in loop
Do While IsSendComplete = False
If sStop Then Exit Function
Tmr = Timer - start
DoEvents
If Tmr > 10 Then
WaitForSendComplete = False
IsSendComplete = False
Exit Function
End If
Loop
WaitForSendComplete = True
IsSendComplete = False
End Function
下面是我写的一段发送邮件控件的源代码的核心部分,没有优化而且时临时摘出来的有些东东没定义,你把它删掉就行,你看看吧
Private Sub wskSend_DataArrival(ByVal bytesTotal As Long)
On Error Resume Next
wskSend.GetData Response ' Check for incoming response *IMPORTANT*
End SubPrivate Sub wskSend_SendComplete()
IsSendComplete = True
End SubPrivate Sub wskSend_SendProgress(ByVal bytesSent As Long, ByVal bytesRemaining As Long)
IsSendComplete = IsSendComplete
End SubPrivate Sub SendEmailFile(DATA As String, MailServerName As String, Port As String, FromEmailAddress As String, ToEmailAddress() As String)
Dim Temp As String
Dim DateNow As String
Dim First As String
Dim Second As String
Dim Rate As Integer
Dim I As LongwskSend.Close
wskSend.LocalPort = 0
PB.Value = 0
timMov.Interval = 150
sStop = False
If wskSend.State = sckClosed Then
DateNow = Format(Date, "Ddd") & ", " & Format(Date, "dd Mmm YYYY") & " " & Format(Time, "hh:mm:ss") & "" & " -0800"
First = "mail from:" + Chr(32) + FromEmailAddress + vbCrLf
wskSend.Close
wskSend.Protocol = sckTCPProtocol
wskSend.RemoteHost = MailServerName '"192.168.0.101"
wskSend.RemotePort = CInt(Port)
wskSend.Connect
If Not WaitFor("220") Then Exit Sub
PutState "正在连接 SMTP 服务器 ..."
If sStop Then Exit Sub
wskSend.SendData ("HELO worldcomputers.com" + vbCrLf)
If Not WaitFor("250") Then Exit Sub
PutState "已经连接服务器"
If sStop Then Exit Sub
wskSend.SendData (First)
PutState "正在发送信笺内容"
If Not WaitFor("250") Then Exit Sub
If sStop Then Exit Sub
For I = LBound(ToEmailAddress) To UBound(ToEmailAddress)
Second = "rcpt to:" + Chr(32) + ToEmailAddress(I) + vbCrLf
wskSend.SendData (Second)
If Not WaitFor("250") Then Exit Sub
Next I
If sStop Then Exit Sub
wskSend.SendData ("data" + vbCrLf)
If Not WaitFor("354") Then Exit Sub
If sStop Then Exit Sub
Dim s As String
Dim iLen As Long
I = 1
iLen = Len(DATA)
Do While (I <= iLen)
PutState CStr(Rate) & "%", Rate
If sStop Then Exit Sub
wskSend.SendData Mid(DATA, I, 2000)
I = I + 2000
Rate = 100 * (I / iLen)
If WaitForSendComplete = False Then
Exit Sub
End If
Loop
If sStop Then Exit Sub
wskSend.SendData (vbCrLf + "." + vbCrLf)
If Not WaitFor("250") Then Exit Sub
If sStop Then Exit Sub
wskSend.SendData ("quit" + vbCrLf)
PutState "正在与服务器断开连接"
If Not WaitFor("221") Then Exit Sub
wskSend.Close
PutState "发送成功。"
timMov.Interval = 0
PB.Value = 100
wskSend.Close
Else
PutState "发送信件过程中出错。"
End If
End SubPrivate Function WaitFor(ResponseCode As String) As Boolean
Dim start
Dim Tmr
Response = "" ' Sent response code to blank **IMPORTANT**
start = Timer ' Time event so won't get stuck in loop
WaitFor = True
Do While Response = ""
If sStop Then Exit Function
Tmr = Timer - start
DoEvents
' DoEvents
' DoEvents ' Let System keep checking for incoming response **IMPORTANT**
If Tmr > 50 Then ' Time in seconds to wait
MsgBox "服务器相应超时!", vbOKOnly, "蓝鸽-SMTP 1.0b"
WaitFor = False
Exit Function
End If
Loop
' While Left(Response, 3) <> ResponseCode
' DoEvents
' If Tmr > 50 Then
' MsgBox "服务器响应错误!", vbOKOnly
' WaitFor = False
' Exit Function
' End If
' Wend
If Left(Response, 3) <> ResponseCode Then
DoEvents
If sStop Then Exit Function
MsgBox "服务器不接受指令: " & Mid(Response, 4), vbOKOnly, "蓝鸽-SMTP 1.0b"
WaitFor = False
Exit Function
End If
End FunctionPrivate Function WaitForSendComplete() As Boolean
Dim start
Dim Tmr
start = Timer ' Time event so won't get stuck in loop
Do While IsSendComplete = False
If sStop Then Exit Function
Tmr = Timer - start
DoEvents
If Tmr > 10 Then
WaitForSendComplete = False
IsSendComplete = False
Exit Function
End If
Loop
WaitForSendComplete = True
IsSendComplete = False
End Function
呕不!太长了总之你看一下MIME协议的RFC吧
更长
还使用Microsoft MAPI Controls中的MAPIMessage控件吧。点一下属性方法很容易懂。
不过是DELPHI编写的。
wyo(欧亚大陆桥),如果能用,明天我会告诉你来领分的,谢谢了!
wyo(欧亚大陆桥)
如果你明天还手不到,我上摘到望上给你下在!!!
请到下面URL领取另外的100分!!!
http://www.csdn.net/expert/topic/138/138173.shtm
只好先委屈一下WYO(欧亚大陆桥),你多等会儿吧,你的交通便利,人家要从南海赶来,多不容易呀!^_^!
@_@
[email protected]
我会给你分的!
发到你信箱了,给100分.我也要混进专家榜了.........
怎么这么好混?我是这个月才从网易(真破!除了成人聊天...)转会过来的.
20日左右才认真回答别人的问题.现在已经600多了,真好混.专家真容易当.哈哈...
你竟然跟我争生意???to shawls(小山)
我也送给你,呵呵!
现在,我宣布颁奖大会到此结束,请两位把奖金拿好了,小心小偷呀!二位走好........
@_@
我只要50分。呵呵,气死:wyo(欧亚大陆桥) !!!
你这老狐狸,呵呵。我以后一定捧你的场!!!
到俺这二道贩子这儿来看看货吧,保证不让你失望,50分,提供相应源码、文章、控件近20个,如何,先别晕...
你这老狐狸!!!呵呵!
都是兄弟,争什么,我刚满月,你都老大不小了。要分吗?小弟给你就是。
Have fun!!!
@_@
开玩笑而已。我今年22不到,还没老呢!