如何使用批处理文件或脚本将邮件从一个Gmail帐户发送到另一个Gmail帐户? [英] How to send an email from one Gmail account to another one using a batch file or script?

查看:272
本文介绍了如何使用批处理文件或脚本将邮件从一个Gmail帐户发送到另一个Gmail帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个小型的Windows脚本来向Gmail帐户发送1行电子邮件。我已经尝试了许多声称这样做的公用事业,如BLAT,但没有工作。如果满足某些条件,脚本将在批处理文件中执行。脚本可以在Perl,Python,VBScript,Java中,只要从批处理文件执行,就没关系。只有通过从Gmail,Hotmail或Yahoo电子邮件帐户发送电子邮件到Gmail帐户,您才可以尝试解决方案。我默认使用的帐户是Gmail,因此我从Gmail帐户发送到Gmail帐户。

I need a tiny Windows script to send a 1 line email to Gmail accounts. I have tried many utilities that claim to do this such as BLAT, but none work. The script will be executed inside a batch file if certain conditions are met. Script can be in Perl, Python, VBScript, Java, it does not matter as long as it executes from a batch file. Please only answer if you have tried your solution by sending an email to a Gmail account from either a Gmail, Hotmail or Yahoo email account. The account I am using by default is Gmail, so I am sending from a Gmail account to a Gmail account.

推荐答案

Blat 可让您直接从批处理文件发送电子邮件:

Blat lets you send e-mails directly from batch files:

blat.exe - -f from@example.com -to to@gmail.com -s Subject -body "Text body" ^
  -server smtp.example.com:25 -u username -pw password

但是似乎Blat不支持SSL,所以要做它与Gmail配合使用,您需要一个额外的工具 Stunnel (参见这里这里)。

But it seems that Blat doesn't support SSL, so to make it work with the Gmail you need an additional tool called Stunnel (see here and here).

无论如何,您应该可以通过GMail从VBScript发送电子邮件使用协作数据对象(CDO) COM API:

Anyway, you should be able to send an e-mail via GMail from VBScript using the Collaboration Data Objects (CDO) COM API:

Const schema   = "http://schemas.microsoft.com/cdo/configuration/"
Const cdoBasic = 1
Const cdoSendUsingPort = 2
Dim oMsg, oConf

' E-mail properties
Set oMsg      = CreateObject("CDO.Message")
oMsg.From     = "from@gmail.com"  ' or "Sender Name <from@gmail.com>"
oMsg.To       = "to@gmail.com"    ' or "Recipient Name <to@gmail.com>"
oMsg.Subject  = "Subject"
oMsg.TextBody = "Text body"

' GMail SMTP server configuration and authentication info
Set oConf = oMsg.Configuration
oConf.Fields(schema & "smtpserver")       = "smtp.gmail.com"
oConf.Fields(schema & "smtpserverport")   = 465
oConf.Fields(schema & "sendusing")        = cdoSendUsingPort
oConf.Fields(schema & "smtpauthenticate") = cdoBasic
oConf.Fields(schema & "smtpusessl")       = True
oConf.Fields(schema & "sendusername")     = "from@gmail.com"
oConf.Fields(schema & "sendpassword")     = "sender_password"
oConf.Fields.Update

oMsg.Send

编辑:添加了缺少的 sendusing 参数,所以现在应该可以正常工作。

Added the lacking sendusing parameter so it should work fine now.

请参阅这里获得更多CDO示例。

See here for more CDO examples.

这篇关于如何使用批处理文件或脚本将邮件从一个Gmail帐户发送到另一个Gmail帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆