0

VBA と CDO を使用し、AOL サーバー経由で Excel から電子メールを送信しています。

私の問題は、それが単に信頼できないということです。おそらく半分の時間で動作しますが、ほとんどの場合、「サーバーへの接続に失敗しました」というメッセージが表示されます。これは私のコードの問題ですか、それとも AOL の問題ですか?

AOL の問題だと思われる場合は、Gmail アカウントを作成してそこから送信することもできますが、私のプライマリ アドレスは AOL のアドレスなので、できれば機能させたいと考えています。

Function SendMail(emSendTo As String, emSubject As String, emBody As String, _
        Optional emMerge As String = "", Optional emAttach As String = "", Optional emBCC As Boolean = True)
    'This email send method uses microsoft CDO library to send email over the web via SMTP, no need for Outlook
    'Comes from my email address so I see replies. Must enable reference to CDO library for spreadsheet
    Dim oMessage As Object
    Dim oCDOConfig As Object
    Dim oSMTPConfig As Variant

    'configure for email via SMTP
    Set oMessage = CreateObject("CDO.Message")
    On Error GoTo Error_Handling
    
    Set oCDOConfig = CreateObject("CDO.Configuration")
    oCDOConfig.Load -1
    
    Set oSMTPConfig = oCDOConfig.Fields
    With oSMTPConfig
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.aol.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "MyEmailAddress@aol.com"
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "wynljiefrzinhumg"
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10
        .Update
    End With
    
    With oMessage
        Set .Configuration = oCDOConfig
    End With
    
    oMessage.Subject = emSubject
    oMessage.From = "MyEmailAddress@aol.com"
    oMessage.To = emSendTo
    
    'if mail is not being sent to me, then BCC me
    If emSendTo <> "MyEmailAddress@aol.com" And emBCC = True Then
        oMessage.BCC = "MyEmailAddress@aol.com"
    End If
    
    'if a mail merge path is specified, then mail merge and send an HTML email, otherwise use body text
    If emMerge = "" Then
        oMessage.TextBody = emBody
    Else
        Call VQSMailMerge(emMerge, oMessage)
    End If
    
    'if an attachment file path is specified then attach it to email
    If emAttach <> "" Then
        oMessage.AddAttachment (emAttach)
    End If

    oMessage.Send
Error_Handling:
    If Err.Description <> "" Then MsgBox "Error emailing, " & Err.Description & " to " & emSendTo
    
End Function
4

0 に答える 0