发邮件代码(主题、内容、附件),邮箱地址仔细检查过了,未有错,为何不能成功。请高手指点一下。
'引用Jmail 4.0 Library
Dim msg As jmail.Message
    Dim strarr, contentId
    Dim bln As Boolean
    Dim intx As Integer    On Error GoTo ErrorHandle    Set msg = CreateObject("JMail.Message")
    msg.Logging = True     '启用邮件日志
    msg.Charset = "gb2312" '邮件的文字编码为国标
    msg.AddRecipient txtSendTo.Text  '邮件收件人的地址
    
    msg.From = txtaddress.Text   '发件人的E-MAIL地址
    msg.MailServerUserName = txtUserName.Text '登录邮件服务器所需的用户名 
    msg.MailServerPassWord = txtPassword.Text ''登录邮件服务器所需的密码
    msg.subject = Format(Date, "yyyy年mm月dd") & "日调试信息" ' '邮件的标题
    msg.Body = "详情见附件。"        ' '邮件的内容   
    
    msg.Priority = 3 ' '邮件的紧急程度,1 为最快,5 为最慢。 3 为默认值,表示中等
    msg.ContentTransferEncoding = "base64"
    If txtFileName.Text <> "" Then '附件
        If Dir(txtFileName.Text) <> "" Then
            contentId = msg.AddAttachment(txtFileName.Text, True) '
        End If
    End If
    If msg.Send(txtUserName.Text & ":" & txtPassword.Text & "@smtp.163.com") Then
        MsgBox "OK!!"
    End If
    msg.Close
Set msg = Nothing

解决方案 »

  1.   

    增加了一句代码:
    msg.FromName = "XXXX" '发送者姓名
    尝试,提示发送成功,可是进入邮箱,未收到任何信息!
    请高手指点一下。是不是附件不接受文本文件(我的附件yyyymmdd.txt)呀!
      

  2.   

    http://blog.csdn.net/Surpass/archive/2004/08/23/82373.aspxFunction SendMail(ByVal From As String, _
                    ByVal Recipient As String, _
                    ByVal RecipientCC As String, _
                    ByVal RecipientBCC As String, _
                    ByVal Subject As String, _
                    ByVal Body As String, _
                    ByVal Attachment As String, _
                    ByVal Priority As Integer, _
                    ByVal MailServer As String, _
                    ByVal MailServerUserName As String, _
                    ByVal MailServerPassWord As String) As Boolean        'From                 发送地址
            'Recipient            接收地址
            'RecipientCC          副本抄送
            'RecipientBCC         隐藏的副本抄送
            'Subject              邮件标题
            'Body                 邮件内容
            'Attachment           附件
            'Priority             邮件的优先程度,从1到5
            'MailServer           SMTP服务器的IP地址或名称
            'MailServerUserName   SMTP服务器用户名
            'MailServerPassWord   SMTP服务器密码        Dim eMail As New jmail.Message
            With eMail
                .Logging = True '调用Log记录,供Debug用
                .Silent = True            .MailServerUserName = MailServerUserName  'SMTP服务器用户名
                .MailServerPassWord = MailServerPassWord  'SMTP服务器密码
                .From = From                                  '发送地址
                .AddRecipient (Recipient)                 '接收地址
                .AddRecipientBCC (RecipientBCC)           '隐藏的副本抄送
                .AddRecipientCC (RecipientCC)                '副本抄送
                .Subject = Subject                        '邮件标题
                .Body = Body                               '邮件内容
                If Len(Attachment) > 0 Then .AddAttachment (Attachment) '附件
                .Priority = Priority            If eMail.Send(MailServer) Then            '发送到SMTP服务器
                    SendMail = True
                Else
                    SendMail = False
                End If
            End With
            DoEvents
            Set eMail = Nothing    '销毁实例
    End Function
      

  3.   

    Dim cSubject As String, cBody As String, cFile As String
    cSubject = Format(Date, "yyyy年mm月dd") & "日调试信息" ' '邮件的标题
    cBody = "详情见附件。"       ' '邮件的内容
     If txtFileName.Text <> "" Then '附件
       If Dir(txtFileName.Text) <> "" Then
         cFile = Trim(txtFileName.Text) '附件文件的绝对地址
       End If
     End If
    If SendMail("[email protected]", "[email protected]", "", "", cSubject, cBody, cFile, 3, "smtp.sina.com.cn", "test200610", "123456") = True Then
       msgbox "发送成功!OK。"
    End If