2017-01-17 15 views
0

VBAでSMTP経由で電子メールを送信しようとしていますが、エラーが返されます。OutlookなしでVBA経由で電子メールを送信する方法

Dim CDOmsg As CDO.Message 
Set CDOmsg = New CDO.Message 

With CDOmsg.Configuration.Fields 
    .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/smtpserver") = "smtp.gmail.com" 
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "[email protected]" 
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "mypass" 
    .Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 465 
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method 
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 
    .Update 
End With 
' build email parts 
With CDOmsg 
    .Subject = "the email subject" 
    .From = "[email protected]" 
    .To = "[email protected]" 
    .CC = "" 
    .BCC = "" 
    .TextBody = "the full message body goes here. you may want to create a variable to hold the text" 
End With 
CDOmsg.Send 
Set CDOmsg = Nothing 

エラーはCDOmsg.Sendにあります。 GmailとYahoo Mailで送信しようとしましたが、同じエラーが表示されます。

エラーコード:-2147220973(80040213)

エラーの説明:トランスポートは、あなたが次のことを試すことができますが、チェックボックスをチェックすることを忘れないでください

答えて

0

サーバーへの接続に失敗しました「Windows 2000ライブラリのMicrosoft CDO」

Function email(ByVal sender_email As String, _ 
      ByVal email_message As String, _ 
      ByVal email_message2 As String, _ 
      ByVal reply_address As String, _ 
      ByVal sender_name As String)  

    Dim Mail As New Message 

    Dim Cfg As Configuration 

    Set Cfg = Mail.Configuration 

    'SETUP MAIL CONFIGURATION FIELDS 
    Cfg(cdoSendUsingMethod) = cdoSendUsingPort 
    Cfg(cdoSMTPServer) = 'SMTP 
    Cfg(cdoSMTPServerPort) = 'SMTPport 
    Cfg(cdoSMTPAuthenticate) = cdoBasic 
    Cfg(cdoSMTPUseSSL) = True 
    Cfg(cdoSendUserName) = 'sender_email 
    Cfg(cdoSendPassword) = 'password 
    Cfg.Fields.Update 

    'SEND EMAIL 
    With Mail 
     .From = 'sender_name & sender_email 
     .ReplyTo = 'reply_address 
     .To = 'receiver 
     .CC = 'carbonCopy 
     .BCC = 'blindCopy 
     .Subject = 'SubjectLine 
     .HTMLBody = 'email_message & email_message2 
     .Attachments.Add attFilePath 
     .Send 
    End With   
関連する問題