VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)
首页 - 经验之谈 - 用Sockets发送电子邮件
发表评论(0)作者:, 平台:, 阅读:9563, 日期:2000-03-25
用Sockets发送电子邮件

想必大多数程序员都是运用Microsoft MAPI控件来发送电子邮件。那你有没有想过其它方法呢?其实,只需简单到4个参数,通过WinSock也可以发电子邮件,不信?

在Form中添加一个WinSock控件,命名为Socket。

Function SendMail(psTo As String, psFrom As String, psSubject As String, psBody As String) As Boolean

Dim lsMessage As String

Dim lsSep As String

lsMessage = "MAIL FROM: <" & psFrom & ">" & vbCrLf _

& "RCPT TO: <" & psTo & ">" & vbCrLf _

& "DATA" & vbCrLf _

& "DATE: " & Format$(Now, "dd mmm yy ttttt") & vbCrLf _

& "FROM: " & psFrom & vbCrLf _

& "TO: " & psTo & vbCrLf _

& "SUBJECT: " & psSubject & vbCrLf & vbCrLf _

& psBody & vbCrLf & "." & vbCrLf

Socket.SendData (lsMessage)

End Function

其中,psFrom是发送人的地址,psTo是收件人的地址,psSubject是邮件主题,psBody是邮件内容。

如何,够简单吧。