SendMail Not Working When Sending Multiple Attachments
Hello, we're having trouble using the builtin function SendMail when sending more than one attachment. It works fine if we simply call the function and pass in our arguments. But when we call the function from our wrapper function we get an error stating "The files you want to attach to the message do not exist". Our wrapper function takes the attachments as an array and iterates through the array to form a comma-separated list which is passed to SendMail along with the other six arguments. When a breakpoint is set at the point where we're calling SendMail the attachments argument correctly evaluates to the comma-separated quoted strings we're expecting (e.g., "F:\Documents\attachment_1.txt", "F:\Documents\attachment_2.txt") so we don't understand why we're getting the error.
Solved! Go to Solution.
[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
Thanks for the suggestion. I used the vbscript Replace function to replace \ with \\ but got the same result. Looking at the SmartBear documentation I ran across a section on using CDO that looks promising. I think I'll give that a try.
Thank you tristaanogre!
Hi @Lance_101 , did you find a solution for this? Please let us know if you still need help from the Community.
Community and Education Specialist
After taking a closer look at CDO it looks like it's been deprecated. The SmartBear documentation page provided a link to further documentation, when you follow that it takes you to a page dated 8/19/2015 that begins by stating: 'This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.' The example code provided by SmartBear contains a URL that's used to setup config parameters, when you follow that you get a 404 error. So I ended up adding a Select/Case statement to the wrapper function that's calling SendMail that can handle up to 6 attachments. Not very elegant but it works. But in speaking with our Infrastructure group it looks like we may not be able to use SendMail after all as there is no option for configuring a port number or to invoke an encryption method, which it appears we will need to do in order to comply with forthcoming company email standards. Can you tell me if there's any way to specify a port number? If not, can you tell me what port number SendMail uses? Also, is there a way to implement some kind of encryption such as SSL or TLS?
The CDO object is indeed no longer actively maintained by Microsoft, but you can still use it for sending emails (the schema still works even though its URL cannot be opened in a browser). Besides, using CDO allows you to specify the SMTP server port and use SSL for SMTP connections.
As for the original issue with multiple attachments, it looks like the issue was with the parameter type. The SendEmail method expects each string to be passed individually, but instead, an entire array of strings was passed in a single parameter. At the same time, SendEmail always uses port 25 and doesn't allow using SSL, so it looks like using CDO will be a more appropriate solution.
SmartBear Customer Care Manager - TestComplete
Thanks for the info regarding CDO. If it can still be used for sending email it may be just what we need as it allows you to specify a port number and to use SSL, as you pointed out. While doing some additional research I came across a post at the following link: https://community.smartbear.com/t5/TestComplete-General-Discussions/Send-mail-via-CDO-doesn-t-work-i... . It describes an issue where CDO was working in Windows 7 but is failing in Windows 10. I don't see that this issue was ever resolved. We are using Windows 10 so before delving into trying to implement CDO can you tell me if that issue was ever resolved?
There are no problems with CDO on the TestComplete side - it simply provides access to the Microsoft component. I assume that the issue described in https://community.smartbear.com/t5/TestComplete-General-Discussions/Send-mail-via-CDO-doesn-t-work-i... was local, probably related to the configuration of the machine.
Using CDO does not require any special implementation - you can simply copy the script from the Sending Email From Scripts article - just in case, I checked it and it works on Windows 10 machines. All that's needed from your side to use CDO is to provide the credentials, the SMTP server address and port and the message details (subject, body, attachments).
SmartBear Customer Care Manager - TestComplete