2

I was using the following code with windows 7 and everything was working, but when I use the same code on windows 10, it stopped working and gave me the error found below further down;

Code that used to work for me in 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()

In windows 10 it is giving me the following error;

Error: 0x800CCE05 Source: CDO.Message.1 Description: The requested body part was not found in this message HelpFile (Null) HelpContext: 0

Specifically from; ;bla bla bla working code -------> pmsg.From :="""John Agius"" "

Could someone please help me? I really need this to work for my job.

Thanks

John Agius

John Agius
  • 35
  • 1
  • 2
  • 8
  • Possible duplicate of [Base64 images to gmail](http://stackoverflow.com/questions/3279523/base64-images-to-gmail) – rds Jan 31 '17 at 13:14

1 Answers1

2

Well, the error is talking about a missing body. So You are probably missing an actual text message in your email (TextBody or HtmlBody). Is your variable emailtosomeone defined?
Try this code:

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

Forivin
  • 14,780
  • 27
  • 106
  • 199
  • Thanks, for some reason, after I edited this code it worked. Even my old code started to work. I have no idea what happened. – John Agius Feb 01 '17 at 16:58
  • @JohnAgius If your problem is not reproducible, you might want to consider deleting your question. On the other hand, if this answer helped to solve your problem, please accept it. After all, it is a good code example. – MCL Feb 02 '17 at 09:29