必须发出STARTTLS错误才能在vbscript中发送电子邮件

时间:2016-07-23 19:17:50

标签: email vbscript

我尝试编写一个vbscript,将带有一些附件的电子邮件发送到另一封电子邮件。但是当我尝试在窗口cmd中执行脚本时,它会显示错误消息“服务器拒绝发送者。服务器响应为530 5.7.0。必须发出STARTLS”

我尝试将端口更改为465或587以用于Google SMTP端口/加密。但它也没有工作

以下是我的vbscript:

Set email = CreateObject("CDO.Message")
email.Subject = "Test Email"
email.From = "kai7@gmail.com"
email.To = "kol@gmail.com"
email.TextBody = "Message Text."
email.AddAttachment "C:\Users\name\Desktop\Handover\v.txt"
email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
email.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
email.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")      = true 
email.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")    = "username"
email.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")    = "password"
email.Configuration.Fields.Update
email.Send
set email = Nothing

2 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,但是尝试通过端口587发送到smtp.office365.com。为我解决的问题是将端口更改为25:

objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.office365.com"
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2     objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objCDOSYSCon.Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 10

答案 1 :(得分:0)

emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 

你错过了一个字段。

检查您正在使用的帐户的收件箱。由于新计划的签名,谷歌阻止了你。 点击谷歌电子邮件中的链接

这是我的完整脚本,用户/密码已空白。确保您的帐户的行正确无误。

在命令提示符下运行此功能,您不必单击“确定”20次,

cscript //nologo script.vbs

Script.vbs

On Error Resume next
Set emailObj      = CreateObject("CDO.Message")
emailObj.From     = "dc@gmail.com"

emailObj.To       = "dc@gmail.com"

emailObj.Subject  = "Test CDO"
emailObj.TextBody = "Test CDO"

Set emailConfig = emailObj.Configuration

For each f in emailConfig.Fields
    wscript.echo f.name & " " & f
Next

msgbox emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") 


emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing")    = 2  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1  
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl")      = true 
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername")    = "Dc"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword")    = "MyPassword"
emailConfig.Fields.Update

emailObj.Send

wscript.echo err.description

For each f in emailConfig.Fields
    wscript.echo f.name & " " & f
Next



If err.number = 0 then Msgbox "Done"