以前能用VB程序发邮件,现在那个邮箱系统增加了个“SMTP服务器需要身份验证”,用VB程序不能出邮件了,如何解决?如何实现“SMTP服务器需要身份验证”,请高手给点代码,谢谢

解决方案 »

  1.   

    在 Outlook 里设置好,用 VBA 写。
      

  2.   

    Dim OutLooks As New Outlook.ApplicationPrivate Sub Command1_Click()
        Call send_mail("Then IA CODE is going to run out!")
    End SubPublic Function OutLookMailto(OutLooks As Outlook.Application, _
            ByVal strSubject As String, _
            ByVal strText As String, colAddrList As Collection, _
            colAttachments As Collection) As Boolean
        Dim Mail As MailItem
        Dim strTemp
        Set Mail = OutLooks.CreateItem(olMailItem)  '設定要一個新的Mail Item
        With Mail
        For Each strTemp In colAddrList
            .Recipients.Add strTemp  '新增收件人
        Next
        '     For Each strTemp In colAttachments
        '         .Attachments.Add strTemp   'Attach的File
        '     Next
        .Subject = strSubject   '主旨
        .Body = strText         '內容
        .Save                   '存入寄件夾
        .Send                   '出信件
        End With
        Set Mail = Nothing
        OutLookMailto = True
        Exit Function
    Errh:
     OutLookMailto = False
    End FunctionPrivate Sub send_mail(ByVal strSubject As String)
        Dim colAddrs As New Collection
        Dim colAttachs As New Collection
        Dim strBody As String
        Dim strText As String
        Dim blnSendOK As Boolean
        Dim SQL As String
        '   SQL = "select email_address from sftm40 where email_group = 'ME'"
        '   Set RS = DB.Execute(SQL)
        ' strBody = "您好:" & vbCrLf & " 您看到這封信時表示已成功傳送"
        'While Not RS.EOF
        colAddrs.Add "[email protected]" '"[email protected]" 'Trim(RS.Fields("email_address"))
        '   RS.MoveNext
        'Wend
        'colAttachs.Add mFile
        colAttachs.Add ""
        strText = " The has already run out, please send the new range to Arima S/W team.&" _
                & " Thank you very much! This mail for test program. "
        blnSendOK = OutLookMailto(OutLooks, strSubject, strText, colAddrs, colAttachs)
        If blnSendOK = True Then
            MsgBox "郵件發送成功!", vbInformation
        Else
            MsgBox "郵件發送未成功!", vbInformation
        End If
        'End
    End Sub
      

  3.   

    请问上面代码需要outlook里设置吗?
      

  4.   

    到网上找一个支持SMTP验证的邮件发送的控件,很多的。