VB发邮件1

'///
'
'   本程序为简邮邮件组件的演示程序
'
'   作者:    三毛
'   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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值