2017-12-29 40 views
1

私は、Microsoft Office Excel 2007 VBAコードでメールを送信しようとしているが、私はエラーを取得しています:エクセルVBA CDOメール

Run-time error '-2147220973 (80040213)':

Automation error

私が使用しているコードは次のとおりです。

Dim cdomsg As Object 

Set cdomsg = CreateObject("CDO.message") 

With cdomsg.Configuration.Fields 

    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
    .Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 25 
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com" 
    ' .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "excel.**********@gmail.com" 
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "**********123" 
    ' .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True 
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60 
    .Update 

End With 

With cdomsg 

    .Subject = "Automated mail" 
    .From = "excel.**********@gmail.com" 
    .To = "**********@hitbts.com" ' https://temp-mail.org/ 
    .TextBody = "Automated mail" 
    .AddAttachment ("*:\*****\***********\****************\***********\*****\*****.xlsm") 
    .Send 

End With 

Set cdomsg = Nothing 

nslookup、コンピュータのIPと別のIPを入力するとcmdに表示される他のsmptサーバー、サーバー名とアドレスを試しましたが、正しいsmptサーバーがわかりません。答えの後

編集:

将来的にはこの探し誰にも、私が使用して働いていたコードは(this映像から取ら)以下の通りです:

Dim Mail As New Message 
Dim Config As Configuration 
Set Config = Mail.Configuration 

Config(cdoSendUsingMethod) = cdoSendUsingPort 
Config(cdoSMTPServer) = "smtp.gmail.com" 
Config(cdoSMTPServerPort) = 25 
Config(cdoSMTPAuthenticate) = cdoBasic 
Config(cdoSMTPUseSSL) = True 
Config(cdoSendUserName) = "[email protected]" 
Config(cdoSendPassword) = "password123" 
Config.Fields.Update 

Mail.AddAttachment ("C:\path\file.ext") 
Mail.To = "[email protected]" 
Mail.From = Config(cdoSendUserName) 
Mail.Subject = "Email Subject" 
Mail.HTMLBody = "<b>Email Body</b>" 

Mail.Send 

変更することを確認します"[email protected]""password123""C:\path\file.ext""[email protected]"などがあります。

また、VBAの「ツール」メニューの「参照...」オプションで、「Microsoft CDO for Windows 2000 Library」を有効にし、上のリンクのビデオに示すようにOKを押しました。

Direct linkhereから取得したGMailの「安全性の低い」オプションを有効にする。

+1

[this](https://stackoverflow.com/questions/43927471/send-up-arrow-%E2%86%91-character-to-iphone-with-sms-using- vba-and-a-cdo-mail-object)を使用しています。 – Jeeped

+1

次の行にエラーがあります: '.Item(" http://schemas.microsoft.com/cdo/configuration/smptserverport ")= 25'。 ** smptserverport **は** smtpserverport ** – Slaqr

+0

@Slaqrにする必要があります。正しいですが、それでもエラーは修正されませんでした。 – user7393973

答えて

1

Gmailをご使用の場合は、 「安全性の低いアプリ」を有効にすることで違いがあるかどうかをチェックしましたか? Support.google.com Reference