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

查看:25
本文介绍了如何使用批处理文件或脚本将电子邮件从一个 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).

无论如何,您应该能够使用 协作数据对象 (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 帐户发送到另一个帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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