gpt4 book ai didi

vbscript - 无法使用 smtp.gmail.com、vbs 脚本的 587 端口发送邮件

转载 作者:行者123 更新时间:2023-12-04 22:45:32 33 4
gpt4 key购买 nike

我正在尝试使用 vbs 脚本发送邮件,但它不起作用。我正在使用服务器 smtp.gmail.com 和端口 587。奇怪的是,当我将端口更改为 25 时,这会起作用。下面是我正在使用的代码:

    SMTPMail "to", "cc", "TEST", "TEST"


Function SMTPMail(ByVal sTo, ByVal sCc, ByVal sSubject, ByVal sBody)


Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).

Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM

Dim objMessage

set objMessage = CreateObject("CDO.Message")
objMessage.Subject = sSubject
objMessage.Sender = "sender"
objMessage.From = "from"
objMessage.To = sTo
objMessage.CC = sCc
objMessage.TextBody = sBody


'==This section provides the configuration information for the remote SMTP server.

objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"

'Server port (typically 25)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 587

'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "username"

'Your password on the SMTP server
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "password"

'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True

'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update()
objMessage.Send()

End Function

先感谢您。

最佳答案

Gmail 用户可以通过官方网站或使用第一方或第三方应用程序和服务来访问他们的帐户。第一方应用程序是例如谷歌官方的Android Gmail 应用程序,而Thunderbird 和Windows 8 的邮件客户端应用程序是第三方应用程序。

谷歌 announced早在 2014 年 4 月,它将提高其服务的登录安全性,并影响任何向公司发送用户名和密码的应用程序。

该公司当时建议切换到 OAuth 2.0,但直到现在才强制执行。

如果打开新less secure谷歌安全设置下的应用程序页面,你会注意到谷歌默认禁用了访问。

注意:只有当您没有使用 Google Apps 或为帐户启用了双重身份验证时,您才会看到该页面。

您可以在此处翻转开关以再次启用安全性较低的应用程序,以便重新获得访问权限。

enter image description here

端口使用的另一件事是 465 而不是 587
因此,您可以使用端口 试用这个对我有用的 vbscript。 465

EmailSubject = "Sending Email by CDO"
EmailBody = "This is the body of a message sent via" & vbCRLF & _
"a CDO.Message object using SMTP authentication ,with port 465."

Const EmailFrom = "self@gmail.com"
Const EmailFromName = "My Very Own Name"
Const EmailTo = "someone@destination.com"
Const SMTPServer = "smtp.gmail.com"
Const SMTPLogon = "self@gmail.com"
Const SMTPPassword = "gMaIlPaSsWoRd"
Const SMTPSSL = True
Const SMTPPort = 465

Const cdoSendUsingPickup = 1 'Send message using local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using SMTP over TCP/IP networking.

Const cdoAnonymous = 0 ' No authentication
Const cdoBasic = 1 ' BASIC clear text authentication
Const cdoNTLM = 2 ' NTLM, Microsoft proprietary authentication

' First, create the message

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = EmailSubject
objMessage.From = """" & EmailFromName & """ <" & EmailFrom & ">"
objMessage.To = EmailTo
objMessage.TextBody = EmailBody

' Second, configure the server

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = SMTPServer

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = SMTPLogon

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = SMTPPassword

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = SMTPPort

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = SMTPSSL

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60

objMessage.Configuration.Fields.Update
'Now send the message!
On Error Resume Next
objMessage.Send

If Err.Number <> 0 Then
MsgBox Err.Description,16,"Error Sending Mail"
Else
MsgBox "Mail was successfully sent !",64,"Information"
End If

关于vbscript - 无法使用 smtp.gmail.com、vbs 脚本的 587 端口发送邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28605803/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com