cancel
Showing results for 
Search instead for 
Did you mean: 

Send mail via CDO doesn't work in windows 10

Highlighted
New Contributor

Send mail via CDO doesn't work in windows 10

I'm using a script as described in https://support.smartbear.com/testcomplete/docs/scripting/sending-email-from-scripts.html

I use it with gmail account.

It works well in windows 7 but doesn't work in windows 10.

the windows 10 pc has office 2016. 

when I try to send an email I get the error: The requested body part was not found in this message.

when I do a debug I see that all mMessage fields are empty.
 
What can I do?
Please help
 
The code I use:
Function SendEmail_Gmail(mFrom, mTo, mSubject, mBody, mAttachment,mpath)
Dim smtpServer, smtpPort, userLogin, userPassword
Dim authenticationType, useSSL, connectionTimeout
Dim schema, mConfig, mMessage
mFrom="testcomp.unisfair@gmail.com"

smtpServer = "smtp.gmail.com"
smtpPort = 25
userLogin = "myaccount" ' e.g. "abc" if the address is abc@gmail.com
userPassword = "mypassword"
authenticationType = 1 ' cdoBasic
connectionTimeout = 30
' Required by Gmail
useSSL = True

Err.Clear()
On Error Resume Next

schema = "http://schemas.microsoft.com/cdo/configuration/"
Set mConfig = Sys.OleObject("CDO.Configuration")

mConfig.Fields.Item(schema & "sendusing") = 2 ' cdoSendUsingPort
mConfig.Fields.Item(schema & "smtpserver") = smtpServer
mConfig.Fields.Item(schema & "smtpserverport") = smtpPort
mConfig.Fields.Item(schema & "sendusername") = userLogin
mConfig.Fields.Item(schema & "sendpassword") = userPassword
mConfig.Fields.Item(schema & "smtpauthenticate") = authenticationType
mConfig.Fields.Item(schema & "smtpusessl") = useSSL
mConfig.Fields.Item(schema & "smtpconnectiontimeout") = connectionTimeout
mConfig.Fields.Update()

Set mMessage = Sys.OleObject("CDO.Message")
Set mMessage.Configuration = mConfig
mMessage.From = mFrom
mMessage.To = mTo
mMessage.Subject = mSubject
mMessage.HTMLBody = "email body:"&vbCrLf&mpath&vbCrLf&mBody


' If 0 < Len(mAttachment) Then
' mMessage.AddAttachment(mAttachment)
' mMessage.Attachments=false
' End If
mMessage.Fields.Update()

mMessage.Send()

If Err Then
Call Log.Warning("E-mail cannot be sent", Err.Description)
SendEMail = False
Err.Clear()
Else
Log.Message("Message to <" & mTo & "> was successfully sent")
SendEMail = True
End If
End Function
2 REPLIES 2
Highlighted
Community Hero

Re: Send mail via CDO doesn't work in windows 10

Have you tried using the BuildIn.SendMail method (https://support.smartbear.com/testcomplete/docs/reference/program-objects/builtin/sendmail.html)?  That is also in that article you linked to that does not require CDO.


Robert Martin
[Hall of Fame]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Vegas Thrill Rider
Extensions available
Highlighted
New Contributor

Re: Send mail via CDO doesn't work in windows 10

Thanks for the quick reply.
Yes I tried the built in sendmail but unfortunately it doesn't work with gmail because the smtp requires authentication.

 

 

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors