CDO smtp邮件突然不发送

时间:2014-09-01 13:44:18

标签: excel vba email cdo.message

所以我有这个代码用于从Excel VBA发送电子邮件。 代码完美地工作到今天早上,因为没有明显的原因宏工作但没有到达目的地地址! 这是一个SMTP中继问题,如果是这样,我该如何解决? 或者它可能是" http://schemas.microsoft.com/cdo/configuration的问题(我仍然不知道它是如何工作的!是否可以在本地使用模式? 或者我错过了什么! 提前致谢 添

这是宏 - 只更改名称以保护无辜者:)

Sub CDO_Mail()
    Dim iMsg As Object
    Dim iConf As Object
    Dim strbody As String
    Dim Flds As Variant

    Set iMsg = CreateObject("CDO.Message")
    Set iConf = CreateObject("CDO.Configuration")

    iConf.Load -1    ' CDO Source Defaults
    Set Flds = iConf.Fields
    With Flds
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "Mick@mouse.com" 
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "BigSecret"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "auth.smtp.1and1.fr"

        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
        .Update
    End With
        With iMsg
        Set .Configuration = iConf
        .To = "MyEmailAddress@gm.com"
        .CC = ""
        .BCC = ""
        .From = "TheMainMan"
        .Subject = "Important message"
        .TextBody = "BODYTEXT"
        .Send

    End With
End Sub

1 个答案:

答案 0 :(得分:0)

尝试使用早期绑定。这具有使自动完成可用的附加优点。您的配置可以这样设置:

Dim iConf As CDO.Configuration

Set iConf = New CDO.Configuration ' CreateObject("CDO.Configuration")
With iConf.Fields
    .Item(cdoSendUsingMethod) = cdoSendUsingPort
    .Item(cdoSMTPServerPort) = 465
    .Item(cdoSMTPServer) = "auth.smtp.1and1.fr"
    .Item(cdoSendUserName) = "Mick@mouse.com" 
    .Item(cdoSendPassword) = "BigSecret"
    'etc.
    .Update
End With

要使用此功能,您需要设置对CDO库的显式引用:工具>参考>在Microsoft CDO旁边设置复选标记。

CDO reference in VBE