'///
'
' 本程序为简邮邮件组件的演示程序
'
' 作者: 三毛
' QQ:510784518
' 博客:http://hi.baidu.com/suruiqiang
'
'///
Option Explicit
Private Declare Function SendMail Lib "smtp.dll" (ByVal StrSmtpServer As String, ByVal StrUser As String, ByVal StrPass As String, ByVal StrMailFrom As String, ByVal StrMailTo As String, ByVal StrSubject As String, ByVal StrBodyMsg As String) As Long
Private Declare Function GetSmtpError Lib "smtp.dll" (ByVal StrErrMsg As String) As Long
Private Sub CmdSend_Click()
Dim StrErrMsg As String
If CobServer.Text = "" Then
MsgBox "请输入SMTP服务器", vbInformation, "输入不完整"
Exit Sub
End If
If TxtUser.Text = "" Then
MsgBox "请输入你的用户名", vbInformation, "输入不完整"
Exit Sub
End If
If TxtPass.Text = "" Then
MsgBox "请输入你的密码", vbInformation, "输入不完整"
Exit Sub
End If
If TxtMailFrom.Text = "" Then
MsgBox "请输入发件人邮箱,发件人邮箱必须和SMTP服务器及你的用户名匹配", vbInformation, "输入不完整"
Exit Sub
End If
If TxtMailTo.Text = "" Then
MsgBox "请输入收件人邮箱", vbInformation, "输入不完整"
Exit Sub
End If
If TxtSubject.Text = "" Then
MsgBox "请输入邮件标题", vbInformation, "输入不完整"
Exit Sub
End If
If TxtBodyMsg.Text = "" Then
MsgBox "邮件正文不能为空", vbInformation, "输入不完整"
Exit Sub
End If
If SendMail(Trim(CobServer.Text), TxtUser.Text, TxtPass.Text, TxtMailFrom.Text, TxtMailTo.Text, TxtSubject.Text, TxtBodyMsg.Text) Then
MsgBox "邮件发送成功", vbInformation
Else
StrErrMsg = Space(100) '填充缓冲区 这句是必须的 不要遗漏
GetSmtpError StrErrMsg
MsgBox StrErrMsg, vbInformation, "邮件发送失败"
End If
End Sub
Private Sub CobServer_Change()
TxtMailFrom.Text = TxtUser.Text & "@" & IIf(Left(CobServer.Text, 5) = "smtp.", Mid(CobServer.Text, 6), CobServer.Text)
End Sub
Private Sub CobServer_Click()
TxtMailFrom.Text = TxtUser.Text & "@" & IIf(Left(CobServer.Text, 5) = "smtp.", Mid(CobServer.Text, 6), CobServer.Text)
End Sub
Private Sub TxtUser_Change()
TxtMailFrom.Text = TxtUser.Text & "@" & IIf(Left(CobServer.Text, 5) = "smtp.", Mid(CobServer.Text, 6), CobServer.Text)
End Sub
VB发邮件1
最新推荐文章于 2022-03-30 22:15:00 发布