热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

无法使用smtp.gmail.com,端口587从vbs脚本发送邮件

如何解决《无法使用smtp.gmail.com,端口587从vbs脚本发送邮件》经验,为你挑选了1个好方法。

我试图使用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

先感谢您.



1> Hackoo..:

Gmail用户可以在官方网站上访问其帐户,也可以使用第一方或第三方应用和服务.第一方应用程序是Google的Android官方Gmail应用程序,而Thunderbird和Windows 8的邮件客户端应用程序是第三方应用程序.

谷歌于2014年4月宣布,它将改善其服务的登录安全性,并影响向公司发送用户名和密码的任何应用程序.

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

如果您在Google上的安全设置下打开新的不太安全的应用页面,您会发现Google默认禁用了访问权限.

注意:仅当您未使用Google Apps或已为该帐户启用双因素身份验证时,才会看到该页面.

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

在此输入图像描述

端口使用的另一件事是465而不是587 所以你可以尝试使用端口465为我工作的这个Vbscript

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


推荐阅读
  • 请问有谁能帮忙将满足条件的邮件内容弄成一封就将所有的完成啊?我现在满足条件的一个就发送一封,有所有满足的就会发送很多。请帮帮忙!真心感谢!谢谢!!<%@LANGUAGEVBSCRIP ... [详细]
  • 我现在写了这样的函数:FunctionopenConnection()SetcnnCreateObject(ADODB.Connection)cnn.Connec ... [详细]
  • 如何使用Java获取服务器硬件信息和磁盘负载率
    本文介绍了使用Java编程语言获取服务器硬件信息和磁盘负载率的方法。首先在远程服务器上搭建一个支持服务端语言的HTTP服务,并获取服务器的磁盘信息,并将结果输出。然后在本地使用JS编写一个AJAX脚本,远程请求服务端的程序,得到结果并展示给用户。其中还介绍了如何提取硬盘序列号的方法。 ... [详细]
  • 利用Visual Basic开发SAP接口程序初探的方法与原理
    本文介绍了利用Visual Basic开发SAP接口程序的方法与原理,以及SAP R/3系统的特点和二次开发平台ABAP的使用。通过程序接口自动读取SAP R/3的数据表或视图,在外部进行处理和利用水晶报表等工具生成符合中国人习惯的报表样式。具体介绍了RFC调用的原理和模型,并强调本文主要不讨论SAP R/3函数的开发,而是针对使用SAP的公司的非ABAP开发人员提供了初步的接口程序开发指导。 ... [详细]
  • 特需要使用集合的时候,无法找到VBScript中的Collection对象;到处找不到,那就自己写一个吧!注:1.需要VBScript5.0或更高版本,使用Class及 ... [详细]
  • <tablecellspacing0cellpadding0>&l ... [详细]
  • 【编程游戏】贺岁霓虹灯。(第一名奖励10000可用分)效果图评分参观[目前Firefox中好使,其他浏览器需复制到本地,存为html文件看效果]<html><head>&l ... [详细]
  • Ihaveasimplequestion,butIvesearchedforthisandcouldntfindanyhelpfultopics..我有一个简单的问 ... [详细]
  • 注意:客户端要装OFFICE下面我就把代码给大家参考一下,希望大家以后能用到。对WORD文档,使用的文字型窗体区域的功能,所有区域定义好以后有个名字,也就是要替换的名字。(替换内容长度可以 ... [详细]
  • Howwouldyouautomateloggingintoawebsiteanddownloadingapageusingvbscript?您如何自动登录网站并使用vbs ... [详细]
  • 动态显示服务器时间的时钟
    现在的BS项目里面有一个要求:在浏览器里面实现显示服务器时间的时钟。如果是显示客户端的时钟倒是很简单了,但是显示服务器段时钟就……。肯定是不能每秒刷新页面了,首先的想法就是取得 ... [详细]
  • 简单U盘修复工具(SURT).hta
    名称:简单U盘修复工具(SURT).hta前言:近段时间发现同学U盘出问题的颇多,每次都拿到我这来修复。其实也没什么大问题,只是中毒了,U盘根目录下的所有东西都被改成了“隐藏+系统+ ... [详细]
  • 本文详细介绍了如何使用MySQL来显示SQL语句的执行时间,并通过MySQL Query Profiler获取CPU和内存使用量以及系统锁和表锁的时间。同时介绍了效能分析的三种方法:瓶颈分析、工作负载分析和基于比率的分析。 ... [详细]
  • 函数代码如下,通讯成功返回True,通讯失败返回False:FunctionPingIP(IP)DimobjWMIService定义SWbemServices对象DimcolIte ... [详细]
  • Linux 中使用 clone 函数来创建线程
    2019独角兽企业重金招聘Python工程师标准Linux上创建线程一般使用的是pthread库实际上libc也给我们提供了创建线程的函数那就是cloneintclone(i ... [详细]
author-avatar
他妈的碧海连天
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有