【问题标题】:Need to send an email (gmail) via SMTP and Autohotkey.需要通过 SMTP 和 Autohotkey 发送电子邮件 (gmail)。
【发布时间】:2017-01-30 15:18:17
【问题描述】:

我在 Windows 7 上使用以下代码并且一切正常,但是当我在 Windows 10 上使用相同的代码时,它停止工作并给了我在下面发现的错误;

曾经在 Windows 7 中为我工作的代码:

pmsg := ComObjCreate("CDO.Message")
pmsg.From := """John Agius"" <something@gmail.com>"
pmsg.To := "somtehting@gmail.com"
pmsg.BCC := ""
pmsg.CC := ""
pmsg.Subject := "Message / Note"
pmsg.TextBody :=emailtosomeone
fields := Object()
fields.smtpserver := "smtp.gmail.com" ; specify your SMTP server
fields.smtpserverport := 465 ; 25
fields.smtpusessl := True ; False
fields.sendusing := 2 ; cdoSendUsingPort
fields.smtpauthenticate := 1 ; cdoBasic
fields.sendusername := "user@gmail.com"
fields.sendpassword := "password"
fields.smtpconnectiontimeout := 60
schema := "http://schemas.microsoft.com/cdo/configuration/"
pfld := pmsg.Configuration.Fields
For field,value in fields
pfld.Item(schema . field) := value
pfld.Update()
pmsg.Send()

在 Windows 10 中,它给了我以下错误;

错误:0x800CCE05 资料来源:CDO.Message.1 说明:在此消息中未找到请求的正文部分 帮助文件(空) 帮助上下文:0

具体来自; ;bla bla bla 工作代码 -------> pmsg.From :="""John Agius"" "

有人可以帮我吗?我真的需要这个来完成我的工作。

谢谢

约翰·阿吉乌斯

【问题讨论】:

标签: gmail autohotkey


【解决方案1】:

嗯,错误是在谈论丢失的身体。因此,您可能在电子邮件(TextBody 或 HtmlBody)中遗漏了一条实际的短信。您的变量 emailtosomeone 是否已定义?
试试这个代码:

pmsg            := ComObjCreate("CDO.Message")
pmsg.From       := """AHKUser"" <...@gmail.com>"
pmsg.To         := "anybody@somewhere.com"
pmsg.BCC        := ""   ; Blind Carbon Copy, Invisable for all, same syntax as CC
pmsg.CC         := "Somebody@somewhere.com, Other-somebody@somewhere.com"
pmsg.Subject    := "Message_Subject"

;You can use either Text or HTML body like
pmsg.TextBody   := "Message_Body"
;OR
;pmsg.HtmlBody := "<html><head><title>Hello</title></head><body><h2>Hello</h2><p>Testing!</p></body></html>"


sAttach         := "Path_Of_Attachment" ; can add multiple attachments, the delimiter is |

fields := Object()
fields.smtpserver   := "smtp.gmail.com" ; specify your SMTP server
fields.smtpserverport     := 465 ; 25
fields.smtpusessl      := True ; False
fields.sendusing     := 2   ; cdoSendUsingPort
fields.smtpauthenticate     := 1   ; cdoBasic
fields.sendusername := "...@gmail.com"
fields.sendpassword := "your_password_here"
fields.smtpconnectiontimeout := 60
schema := "http://schemas.microsoft.com/cdo/configuration/"


pfld :=   pmsg.Configuration.Fields

For field,value in fields
    pfld.Item(schema . field) := value
pfld.Update()

Loop, Parse, sAttach, |, %A_Space%%A_Tab%
  pmsg.AddAttachment(A_LoopField)
pmsg.Send()

https://autohotkey.com/board/topic/60813-cdo-com-email-delivery-ahk-l/#p403177

【讨论】:

  • 谢谢,由于某种原因,在我编辑了这段代码之后它工作了。甚至我的旧代码也开始工作了。我不知道发生了什么。
  • @JohnAgius 如果您的问题无法重现,您可能需要考虑删除您的问题。另一方面,如果此答案有助于解决您的问题,请接受。毕竟是一个很好的代码示例。
猜你喜欢
  • 1970-01-01
  • 2022-08-14
  • 2017-05-12
  • 2020-02-21
  • 2014-01-04
  • 2016-01-16
  • 2015-10-09
  • 2011-08-11
  • 1970-01-01
相关资源
最近更新 更多