本页主题: 有福了,可以发送邮件的类模块(测试通过) 打印 | 加为IE收藏 | 复制链接 | 收藏主题 | 上一主题 | 下一主题

haimin350
级别: 侠客


精华: 1
发帖: 110
威望: 174 点
VB币: 997 个
贡献值: 0 点
在线时间:10(小时)
注册时间:2008-03-22
最后登录:2008-08-07

 有福了,可以发送邮件的类模块(测试通过)

管理提醒:
本帖被 尘与风 设置为精华(2008-06-09)
'Option Compare Database
Option Explicit
'                          \\\|///
'                        \\  - -  //
'                          (  @ @  )
'━━━━━━━━━━━━oOOo-(_)-oOOo━━━━━━━━━━━━━━
'-类名称:      SendMail
'-功能描述:    发送邮件
'-参考:
'-使用注意:
'-兼容性:      2000,XP,2003
'-作者:        fan0217@tom.com
'-更新日期:    2007-08-22
'                            Oooo
'━━━━━━━━━━oooO━-(  )━━━━━━━━━━━━━━━━━
'                    (  )  ) /
'                    \ (  (_/
'                      \_)
Private Const cdoSendUsingMethod = "http://schemas.microsoft.com/cdo/configuration/sendusing"
Private Const cdoSendUsingPort = 2
Private Const cdoSMTPServer = "http://schemas.microsoft.com/cdo/configuration/smtpserver"
Private Const cdoSMTPServerPort = "http://schemas.microsoft.com/cdo/configuration/smtpserverport"
Private Const cdoSMTPConnectionTimeout = "http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout"
Private Const cdoSMTPAuthenticate = "http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"
Private Const cdoBasic = 1
Private Const cdoSendUserName = "http://schemas.microsoft.com/cdo/configuration/sendusername"
Private Const cdoSendPassword = "http://schemas.microsoft.com/cdo/configuration/sendpassword"
Private objConfig ' As CDO.Configuration
Private objMessage ' As CDO.Message
Private Fields ' As ADODB.Fields
Private strSMTPServer As String
Private strSendUserName As String
Private strSendPassword As String
Private strFromMail As String
Private intSMTPConnectionTimeout As Integer
Private intSMTPServerPort As Integer
Public Function Send(toMail As String, subject As String, textBody As String, Optional attachment As String = "") As Boolean
    SendInitialize
    With objMessage
        .to = toMail '接收者的邮件地址
        .From = FromMail '发送人的邮件地址
        .subject = subject '标题
        .textBody = textBody '正文
        If attachment <> "" Then
            .addAttachment attachment '邮件附件
        End If
        .Send
    End With
    Send = True
End Function
Private Sub SendInitialize()
    Set objConfig = CreateObject("CDO.Configuration")
    Set Fields = objConfig.Fields
    With Fields
        .Item(cdoSendUsingMethod) = cdoSendUsingPort
        .Item(cdoSMTPServer) = SMTPServer
        .Item(cdoSMTPServerPort) = SMTPServerPort
        .Item(cdoSMTPConnectionTimeout) = SMTPConnectionTimeout
        .Item(cdoSMTPAuthenticate) = cdoBasic
        .Item(cdoSendUserName) = SendUserName
        .Item(cdoSendPassword) = SendPassword
        .Update
    End With
    Set objMessage = CreateObject("CDO.Message")
    Set objMessage.Configuration = objConfig
End Sub
'可用的外部邮件服务器域名
Public Property Get SMTPServer() As String
    SMTPServer = strSMTPServer
End Property
Public Property Let SMTPServer(ByVal value As String)
    strSMTPServer = value
End Property
'邮件服务器的用户名
Public Property Get SendUserName() As String
    SendUserName = strSendUserName
End Property
Public Property Let SendUserName(ByVal value As String)
    strSendUserName = value
End Property
'邮件服务器的密码
Public Property Get SendPassword() As String
    SendPassword = strSendPassword
End Property
Public Property Let SendPassword(ByVal value As String)
    strSendPassword = value
End Property
'发件人的地址(要和SMTP相同)
Public Property Get FromMail() As String
    FromMail = strFromMail
End Property
Public Property Let FromMail(ByVal value As String)
    strFromMail = value
End Property
Public Property Get SMTPConnectionTimeout() As Integer
    SMTPConnectionTimeout = intSMTPConnectionTimeout
End Property
Public Property Let SMTPConnectionTimeout(ByVal value As Integer)
    intSMTPConnectionTimeout = value
End Property
Public Property Get SMTPServerPort() As Integer
    SMTPServerPort = intSMTPServerPort
End Property
Public Property Let SMTPServerPort(ByVal value As Integer)
    intSMTPServerPort = value
End Property
Private Sub Class_Initialize()
    SMTPServerPort = 25
    SMTPConnectionTimeout = 10
End Sub
Private Sub Class_Terminate()
    Set Fields = Nothing
    Set objMessage = Nothing
    Set objConfig = Nothing
End Sub


发信测试

Sub Test()
Dim s As New SendMail '如果这里出错,就是你没有将类名称修改成:SendMail
s.SMTPServer = "SMTP.163.com"
s.SendUserName = "邮箱帐号"
s.SendPassword = "密码"
s.FromMail = "发信邮箱(jjj@163.com)"
s.Send "收信箱(uuu@qq.com)", "测试邮件", "收到请回复!--" & Now
Set s = Nothing
End Sub

Private Sub Command1_Click()
Test
End Sub
本帖最近评分记录:
  • VB币:+5(尘与风) 好东西!
  • 想要源码的给点思路
    想要思路的给点源码
    kovb@qq.com
    Posted: 2008-06-09 04:20 | [楼 主]
    haimin350
    级别: 侠客


    精华: 1
    发帖: 110
    威望: 174 点
    VB币: 997 个
    贡献值: 0 点
    在线时间:10(小时)
    注册时间:2008-03-22
    最后登录:2008-08-07

     

    想要源码的给点思路
    想要思路的给点源码
    kovb@qq.com
    Posted: 2008-06-09 04:22 | 1 楼
    尘与风
    换个角度思考问题
    可以扭转一切
    级别: 管理员


    精华: 14
    发帖: 350
    威望: 436 点
    VB币: 4916 个
    贡献值: 86 点
    在线时间:114(小时)
    注册时间:2008-04-07
    最后登录:2008-09-05

     

    的确是好东西!下来测试下看看  
    交流,才会进步。
    为了论坛更好的生存,大家有空就帮忙点点广告。
    希望大家支持本论坛,为更多的朋友带来帮助。
    Posted: 2008-06-09 17:44 | 2 楼
    now1000
    我是a'Gao
    级别: 论坛版主


    精华: 0
    发帖: 122
    威望: 133 点
    VB币: 50 个
    贡献值: 0 点
    在线时间:12(小时)
    注册时间:2008-06-21
    最后登录:2008-09-03

     

    楼主可以分惜一下吗!!!1
    许多事情都是注定的!
    Posted: 2008-07-04 12:47 | 3 楼
    now1000
    我是a'Gao
    级别: 论坛版主


    精华: 0
    发帖: 122
    威望: 133 点
    VB币: 50 个
    贡献值: 0 点
    在线时间:12(小时)
    注册时间:2008-06-21
    最后登录:2008-09-03

     

    我不看不懂
    许多事情都是注定的!
    Posted: 2008-07-04 12:51 | 4 楼
    now1000
    我是a'Gao
    级别: 论坛版主


    精华: 0
    发帖: 122
    威望: 133 点
    VB币: 50 个
    贡献值: 0 点
    在线时间:12(小时)
    注册时间:2008-06-21
    最后登录:2008-09-03

     

    我看不懂
    许多事情都是注定的!
    Posted: 2008-07-04 12:52 | 5 楼
    比力棠育
    级别: 新手上路


    精华: 0
    发帖: 6
    威望: 7 点
    VB币: 12 个
    贡献值: 0 点
    在线时间:0(小时)
    注册时间:2008-07-09
    最后登录:2008-07-11

     有搞头

    有搞头,哈哈,楼主不错
    ----------------------------------------------
    个性签名:

    我爱贴图---Welcome to our website for you World of Warcraft Gold wow gold,wow gold,wow gold,wow gold,wow gold,
    .
    哈哈
    Posted: 2008-07-11 02:22 | 6 楼
    帖子浏览记录 版块浏览记录
    VB家园 » 『VB网络编程』



    中华人民共和国信息产业部许可证编号:粤ICP备08023639号 
    Powered by PHPWind v6.0 Certificate Code © 2003-07 PHPWind.com Corporation